View Source

h3. What

# Build ├╝ber jar (jar with all dependencies) file and upload to Maven artifact repository
# Download jar file and upload to S3.
# Deploy lambda

h3. Strategy for DevTest, Systest and Prod environment


We support three environments; Devtest, Systest and Production. Devtest environment is automatically updated with latest and greatest version. Test environment is automatically updated with the latest release. Manual deploy to production. This set up supports continuous delivery, and it is easy to enable continuous deployment when/if we want.

Continuous deployment means that every change is automatically deployed to production. [Continuous delivery|https://en.wikipedia.org/wiki/Continuous_delivery] means that the team ensures every change can be deployed to production, but may choose not to do it.

We use maven profiles to differentiate deployment to different environments. lambda-deploy-devtest/lambda-deploy-systest profiles are using executions to hook into deploy phase and run plugin goal deploy-lambda.

|| Trigger || CI server || Plugin internals || Comment ||
|1. Developer: push to Git \\ 2. mvn clean deploy -Plambda-deploy-devtest |Job: \\clean deploy -U -Plambda-deploy-devtest|alias LATEST and withPublish=false and forceUpdate=true is set in pom.xml | |
|1. CI server: successful mvn release |Release goals and options: \\release:perform -Plambda-deploy-systest |alias <version>* and withPublish=true is set in pom.xml | |
|1. CI server: manually |Job: \\ org.apache.maven.plugins:maven-dependency-plugin:2.10:copy artifact \\mvn lambda:deploy-lambda -Dlambda.functionCode=/tmp/$MVN_RELEASE_VERSION.jar -Dlambda.version=$MVN_RELEASE_VERSION -Plambda-deploy-prod -DremoteRepositories= |alias <version>* and withPublish=true is set in pom.xml |If using the same AWS account for test and prod environment, this deployment can easily be done manually without a CI server job. |

* (version is same as version from jar file, but with "-" instead of ".")


Deploy to production is using http://maven.apache.org/plugins/maven-dependency-plugin/get-mojo.html as a pre step


h3. Dev environment - autodeploy

# Developer: push to Git
# Jenkins: mvn clean deploy -Plambda-deploy-devtest
# Jenkins: on successful build, trigger new step: lambda-maven-plugin
## Download snapshot version from mvn repo and upload to S3
## alias: LATEST (reused)
## withPublish=false, forceUpdate=true

h3. Test environment - autodeploy

# Developer (in Jenkins): trigger mvn release -Plambda-deploy-devtest
# Jenkins: on successful build, trigger new step: lambda-maven-plugin
## Download release version from mvn repo and upload to S3
## alias: <version> (version is same as version from jar file, but with "-" unstead of ".")
## withPublish=true


h3. Production environment - manual

# Developer (in Jenkins): trigger new job: maven-dependency-plugin:copy and lambda-maven-plugin -Plambda-deploy-prod
## Download release from mvn repo
## Upload file to S3 and deploy
## profile:lambda-deploy-prod (reused), <lambda.version> mvn release version
## withPublish=true

{code:title=Example steps for deployment to production}
1 step. Download artifact
org.apache.maven.plugins:maven-dependency-plugin:2.10:copy \
-DoutputDirectory=/tmp \
-Dmdep.stripVersion=false \
-DoverWriteReleases=true \
-DoverWriteIfNewer=true \
-Dartifact=groupId:artifactId:$MVN_RELEASE_VERSION:jar

2 step. Deploy artifact
no.cantara.maven.plugins:lambda-maven-plugin:2.0-beta-1:deploy-lambda \
-Dlambda.functionCode=/tmp/$MVN_RELEASE_VERSION.jar -Dlambda.version=$MVN_RELEASE_VERSION \
-Plambda-deploy-prod
{code}


h3. Example pom.xml configuration using profiles

{code}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
...
<build>
<plugins>
<plugin>
<groupId>no.cantara.maven.plugins</groupId>
<artifactId>lambda-maven-plugin</artifactId>
<version>2.0-beta-2</version>
<configuration>
<functionCode>${lambda.functionCode}</functionCode>
<version>${lambda.version}</version>
<lambdaRoleArn>arn:aws:iam::ID:role/YourRole</lambdaRoleArn>
<s3Bucket>FILE_DESTINATION_BUCKET</s3Bucket>
<lambdaFunctionsJSON>
[
{
"functionName": "function1,
"description": "Example of Function1",
"handler": "no.cantara.Function1",
"topics": ["topic1"]
},
{
"functionName": "function2",
"description": "Example of Function2",
"handler": "no.cantara.Function2"
}
]
</lambdaFunctionsJSON>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>lambda-deploy-devtest</id>
<build>
<plugins>
<plugin>
<groupId>no.cantara.maven.plugins</groupId>
<artifactId>lambda-maven-plugin</artifactId>
<executions>
<execution>
<id>deploy-lambda</id>
<phase>deploy</phase>
<configuration>
<functionNameSuffix>devtest</functionNameSuffix>
<vpcSecurityGroupIds>
<vpcSecurityGroupId>sg-1</vpcSecurityGroupId>
</vpcSecurityGroupIds>
<vpcSubnetIds>
<vpcSubnetId>subnet-1</vpcSubnetId>
<vpcSubnetId>subnet-2</vpcSubnetId>
<vpcSubnetId>subnet-3</vpcSubnetId>
</vpcSubnetIds>
<publish>false</publish>
<forceUpdate>true</forceUpdate>
</configuration>
<goals>
<goal>deploy-lambda</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>lambda-deploy-systest</id>
<build>
<plugins>
<plugin>
<groupId>no.cantara.maven.plugins</groupId>
<artifactId>lambda-maven-plugin</artifactId>
<executions>
<execution>
<id>deploy-lambda</id>
<phase>deploy</phase>
<configuration>
<functionNameSuffix>systest</functionNameSuffix>
<vpcSecurityGroupIds>
<vpcSecurityGroupId>sg-1</vpcSecurityGroupId>
</vpcSecurityGroupIds>
<vpcSubnetIds>
<vpcSubnetId>subnet-1</vpcSubnetId>
<vpcSubnetId>subnet-2</vpcSubnetId>
<vpcSubnetId>subnet-3</vpcSubnetId>
</vpcSubnetIds>
<publish>true</publish>
</configuration>
<goals>
<goal>deploy-lambda</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>lambda-deploy-prod</id>
<build>
<plugins>
<plugin>
<groupId>no.cantara.maven.plugins</groupId>
<artifactId>lambda-maven-plugin</artifactId>
<configuration>
<functionNameSuffix>prod</functionNameSuffix>
<vpcSecurityGroupIds>
<vpcSecurityGroupId>sg-11</vpcSecurityGroupId>
</vpcSecurityGroupIds>
<vpcSubnetIds>
<vpcSubnetId>subnet-22</vpcSubnetId>
<vpcSubnetId>subnet-33</vpcSubnetId>
<vpcSubnetId>subnet-44</vpcSubnetId>
</vpcSubnetIds>
<publish>true</publish>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
{code}

h3. Tech

* Git
* Maven
** https://maven.apache.org/plugins/maven-shade-plugin/
** http://maven.apache.org/maven-release/maven-release-plugin/
* Maven plugin for deloy to AWS Lambda, https://github.com/Cantara/lambduh-maven-plugin
* Jenkins

h3. Read more

* AWS Lambda
** https://aws.amazon.com/documentation/lambda/
** http://docs.aws.amazon.com/lambda/latest/dg/aliases-intro.html
** https://aws.amazon.com/blogs/compute/new-deployment-options-for-aws-lambda/
* Maven
** https://maven.apache.org/plugins/maven-shade-plugin/
** http://maven.apache.org/maven-release/maven-release-plugin/
** https://github.com/Cantara/lambduh-maven-plugin
*** http://maven.apache.org/plugins/maven-dependency-plugin/get-mojo.html