org.lambadaframework.deployer.Deployment Maven / Gradle / Ivy
The newest version!
package org.lambadaframework.deployer;
import com.amazonaws.services.cloudformation.model.Parameter;
import org.apache.maven.artifact.versioning.OverConstrainedVersionException;
import org.lambadaframework.aws.S3;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.project.MavenProject;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.xml.sax.InputSource;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathFactory;
import java.io.StringReader;
import java.util.*;
public class Deployment {
private static String seperator = "/";
protected String packageName;
protected String stage;
protected String region;
protected Properties properties;
protected MavenProject project;
private static final String deploymentBucketPropertyName = "deployment.bucket";
public static final String LAMBDA_MAXIMUM_EXECUTION_TIME_KEY = "LambdaMaximumExecutionTime";
public static final int LAMBDA_MAXIMUM_EXECUTION_TIME_DEFAULT_VALUE = 3;
public static final String LAMBDA_MEMORY_SIZE_KEY = "LambdaMemorySize";
public static final int LAMBDA_MEMORY_SIZE_DEFAULT_VALUE = 128;
public static final String LAMBDA_EXECUTION_ROLE_POLICY_KEY = "LambdaExecutionRoleManagedPolicyARNs";
public static final String LAMBDA_VPC_SUBNETS_KEY = "SubnetIds";
public static final String LAMBDA_VPC_SECURITY_GROUPS_KEY = "SecurityGroupIds";
public static final String S3_DEPLOYMENT_BUCKET_KEY = "DeploymentS3Bucket";
public static final String S3_DEPLOYMENT_KEY_KEY = "DeploymentS3Key";
public static final String LAMBDA_HANDLER_KEY = "LambdaHandler";
public static final String LAMBDA_HANDLER_DEFAULT_VALUE = "org.lambadaframework.runtime.Handler";
public static final String LAMBDA_DESCRIPTION_KEY = "LambdaDescription";
protected Log log;
public Deployment(MavenProject project,
String packageName,
Properties properties,
String region,
String stage) {
this.project = project;
this.packageName = packageName;
this.region = region;
this.properties = properties;
this.stage = stage;
setDefaultParameters();
}
public void setLog(Log log) {
this.log = log;
}
public String getPackageName() {
return packageName;
}
public String getProjectName() {
return project.getGroupId() + "." + project.getArtifactId();
}
/**
* Sets default Cloudformation Parameters
*/
protected void setDefaultParameters() {
properties.setProperty(S3_DEPLOYMENT_BUCKET_KEY, getBucketName());
properties.setProperty(S3_DEPLOYMENT_KEY_KEY, getJarFileLocationOnS3(getVersion()));
properties.setProperty(LAMBDA_DESCRIPTION_KEY, getLambdaDescription());
if (properties.getProperty(LAMBDA_MAXIMUM_EXECUTION_TIME_KEY) == null) {
properties.setProperty(LAMBDA_MAXIMUM_EXECUTION_TIME_KEY, Integer.toString(LAMBDA_MAXIMUM_EXECUTION_TIME_DEFAULT_VALUE));
}
if (properties.getProperty(LAMBDA_MEMORY_SIZE_KEY) == null) {
properties.setProperty(LAMBDA_MEMORY_SIZE_KEY, Integer.toString(LAMBDA_MEMORY_SIZE_DEFAULT_VALUE));
}
if (properties.getProperty(LAMBDA_HANDLER_KEY) == null) {
properties.setProperty(LAMBDA_HANDLER_KEY, LAMBDA_HANDLER_DEFAULT_VALUE);
}
}
public String getVersion() {
return this.project.getArtifact().getVersion();
}
public String getStage() {
return stage;
}
public String getRegion() {
return region;
}
/**
* Stack name is a combination of Artifact Id and stage
* For every stage we have a different CF Stack, thus different Lambda functions and roles.
*
* @return CF Stack Name
*/
public String getCloudFormationStackName() {
return project.getArtifactId() + "-" + getStage();
}
public Collection getCloudFormationParameters() {
Collection parameters = new ArrayList<>();
for (Map.Entry
© 2015 - 2024 Weber Informatics LLC | Privacy Policy