Deploying from Maven to AWS Beanstalk
Reference:
http://beanstalker.ingenieux.com.br/beanstalk-maven-plugin/usage.html
http://beanstalker.ingenieux.com.br/beanstalk-maven-plugin/configurations-and-templates.html
Security Credentials
Here, you have two options:
Declare as a server on your $HOME/.m2/settings.xml:
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<id>aws.amazon.com</id>
<username>[your aws access key]</username>
<password>[your aws secret key, possibly
encrypted]</password>
</server>
</servers>
</settings>
You can declare domains other than aws.amazon.com - All you
need to do is to set beanstalk.serverId as well. For more information, check
the Maven docs on Password Encryption
It **DOES** support password encryption. In fact, it throws
up an alert whenever it finds an unencrypted password.
Declaring as Environment Variables:
$ export AWS_ACCESS_KEY_ID="<your aws access
key>"
$ export AWS_SECRET_KEY="<your aws secret
key>"
$ mvn beanstalk:upload-source-bundle
Password Encryption using Maven
mvn --encrypt-master-password xxxx
Store this password in the ~/.m2/settings-security.xml; it
should look like
<settingsSecurity>
<master>{4E6QXvddPu1jujsA=}</master>
</settingsSecurity>
When this is done, you can start encrypting existing server
passwords.
mvn --encrypt-password <password>
copy and paste this password in the settings file in server
section as follows,
<server>
<id>aws.amazon.com</id>
<username>foo</username>
<password>{COQLCE6}</password>
</server>
If you have multiple servers defined, just add them with
names other than aws.amazon.com and set the Maven Property beanstalker.serverId
to the server name declared.
Test configurations using
mvn
br.com.ingenieux:beanstalk-maven-plugin:1.1.1:show-security-credentials
-Dbeanstalker.serverId=aws.amazon.com
Should return user information’s
mvn beanstalk:check-availability
-Dbeanstalk.cnamePrefix=Test-v3
Query the application with your environment name look under
Tags in console you can see the envionment name and id
Uploading your
application
Create a bucket in S3,
modify your build plugin as follows,
<build>
<plugins>
<plugin>
<groupId>br.com.ingenieux</groupId>
<artifactId>beanstalk-maven-plugin</artifactId>
<version>[plugin version]</version>
<configuration>
<s3Bucket>[bucket
name]</s3Bucket>
</configuration>
</plugin>
</plugins>
</build>
Setup versioning if you need as follows,
<properties>
<maven.build.timestamp.format>yyyyMMddHHmmss</maven.build.timestamp.format>
<beanstalk.versionLabel>${maven.build.timestamp}</beanstalk.versionLabel>
</properties>
...
<build>
<plugins>
<plugin>
<groupId>br.com.ingenieux</groupId>
<artifactId>beanstalk-maven-plugin</artifactId>
<version>[plugin
version]</version>
<configuration>
<applicationName>[name of your
application]</applicationName>
<s3Bucket>[bucket name]</s3Bucket>
<s3Key>${project.artifactId}/${project.build.finalName}-${maven.build.timestamp}.war</s3Key>
<!-- will
save as s3://[bucket name]/[artifactId]/artifactId-version-TIMESTAMP.war -->
</configuration>
</plugin>
</plugins>
</build>
UPLOAD USING THE FOLLOWING COMMAND: NOTE YOU CAN OVERIDE THE
BUCKET TO UPLOAD AT COMMAND LINE
mvn beanstalk:upload-source-bundle -Ds3Bucket=test-war
CREATING APPLICATION, APPLICATION VERSION AND ENVIRONMENT
mvn beanstalk:upload-source-bundle
beanstalk:create-application-version beanstalk:create-environment
UPDATING
two ways, update existing or create new and switch
1. mvn beanstalk:upload-source-bundle
beanstalk:create-application-version beanstalk:update-environment
2. mvn beanstalk:upload-source-bundle
beanstalk:create-application-version beanstalk:replace-environment
mvn -Ptest beanstalk:upload-source-bundle beanstalk:create-application-version beanstalk:update-environment
Make sure to set the following in the pom,
<beanstalk.environmentRef>txxx.elasticbeanstalk.com</beanstalk.environmentRef>
<beanstalk.environmentDescription>xxx-v1</beanstalk.environmentDescription>
Rolling Back a Version
mvn beanstalk:rollback-version
Cleaning Up Previous Versions - There are two options to
pick: daysToKeep or versionsToKeep. Either way, first it simulates the
execution.
This will do a dry run only will not delete
mvn beanstalk:clean-previous-versions
-Dbeanstalk.versionsToKeep=1
This will delete previous version
mvn beanstalk:clean-previous-versions
-Dbeanstalk.versionsToKeep=1 -Dbeanstalk.dryRun=false
Terminating
mvn beanstalk:terminate-environment
mvn beanstalk:terminate-environment
-Dbeanstalk.environmentId=e-ig6jqpcry7
LISTING Environments
mvn beanstalk:describe-environments
Creating Environment - when everything is in POM
mvn beanstalk:upload-source-bundle
beanstalk:create-application-version beanstalk:create-environment
Use profiles for test and prod
mvn -Ptest beanstalk:upload-source-bundle
beanstalk:create-application-version beanstalk:create-environment
mvn -Pprod beanstalk:upload-source-bundle
beanstalk:create-application-version beanstalk:create-environment
USING AWS CLI to do few things,
To describe environment
aws elasticbeanstalk describe-environments
Change AWS beanstalk environment instance Type
aws elasticbeanstalk update-environment --environment-name Test-v3 --option-settings
Namespace=aws:autoscaling:launchconfiguration,OptionName=InstanceType,Value=t2.micro
Some Parameters for the Beanstalk to put on pom.xml
<properties>
<aws.enviornmentName>service-test-v4</aws.enviornmentName>
<aws.cNamePrefix>test-api-v4</aws.cNamePrefix>
<aws.applicationName>Service Test</aws.applicationName>
<aws.enviornmentRef>test-v4.elasticbeanstalk.com</aws.enviornmentRef>
<beanstalker.serverId>aws.prod.server</beanstalker.serverId>
<aws.solutionStack>64bit Amazon Linux 2014.09 v1.2.0 running Tomcat 8 Java 8
</aws.solutionStack>
<aws.EnvironmentType>SingleInstance</aws.EnvironmentType>
<aws.instanceType>m1.small</aws.instanceType>
<beanstalker.region>ap-southeast-2</beanstalker.region>
<maven.build.timestamp.format>yyyyMMddHH</maven.build.timestamp.format>
<beanstalk.versionLabel>${maven.build.timestamp}</beanstalk.versionLabel>
<aws.accessKeyId>XXXX</aws.accessKeyId>
<aws.secretKey>XXXAu4</aws.secretKey>
<aws.App.configurationBucketName>prod-config</aws.App.configurationBucketName>
<aws.s3.bucket.ReleaseLocation>application-releases</aws.s3.bucket.ReleaseLocation>
</properties>
<properties>
<aws.enviornmentName>service-test-v4</aws.enviornmentName>
<aws.cNamePrefix>test-api-v4</aws.cNamePrefix>
<aws.applicationName>Service Test</aws.applicationName>
<aws.enviornmentRef>test-v4.elasticbeanstalk.com</aws.enviornmentRef>
<beanstalker.serverId>aws.prod.server</beanstalker.serverId>
<aws.solutionStack>64bit Amazon Linux 2014.09 v1.2.0 running Tomcat 8 Java 8
</aws.solutionStack>
<aws.EnvironmentType>SingleInstance</aws.EnvironmentType>
<aws.instanceType>m1.small</aws.instanceType>
<beanstalker.region>ap-southeast-2</beanstalker.region>
<maven.build.timestamp.format>yyyyMMddHH</maven.build.timestamp.format>
<beanstalk.versionLabel>${maven.build.timestamp}</beanstalk.versionLabel>
<aws.accessKeyId>XXXX</aws.accessKeyId>
<aws.secretKey>XXXAu4</aws.secretKey>
<aws.App.configurationBucketName>prod-config</aws.App.configurationBucketName>
<aws.s3.bucket.ReleaseLocation>application-releases</aws.s3.bucket.ReleaseLocation>
</properties>
<build>
<plugins>
<plugin>
<groupId>br.com.ingenieux</groupId>
<artifactId>beanstalk-maven-plugin</artifactId>
<version>1.4.0</version>
<configuration>
<region>ap-southeast-2</region>
<environmentName>${aws.enviornmentName}</environmentName>
<cnamePrefix>${aws.cNamePrefix}</cnamePrefix>
<applicationName>${aws.applicationName}</applicationName>
<environmentRef>${aws.enviornmentRef}</environmentRef>
<solutionStack>${aws.solutionStack}</solutionStack>
<useStagingDirectory>true</useStagingDirectory>
<s3Bucket>${aws.s3.bucket.ReleaseLocation}</s3Bucket>
<verbose>true</verbose>
<s3Key>
${project.artifactId}/${project.build.finalName}-${maven.build.timestamp}.war
</s3Key>
<optionSettings>
<setting>
<namespace>aws:elasticbeanstalk:application</namespace>
<optionName>Application Healthcheck URL</optionName>
<value>/</value>
</setting>
<setting>
<namespace>aws:elasticbeanstalk:environment</namespace>
<optionName>EnvironmentType</optionName>
<value>${aws.EnvironmentType}</value>
</setting>
<setting>
<namespace>aws:autoscaling:launchconfiguration</namespace>
<optionName>InstanceType</optionName>
<value>${aws.instanceType}</value>
</setting>
<setting>
<namespace>aws:elasticbeanstalk:application:environment</namespace>
<optionName>AWS_ACCESS_KEY_ID</optionName>
<value>${aws.accessKeyId}</value>
</setting>
<setting>
<namespace>aws:elasticbeanstalk:application:environment</namespace>
<optionName>AWS_SECRET_KEY</optionName>
<value>${aws.secretKey}</value>
</setting>
<setting>
<namespace>aws:elasticbeanstalk:application:environment</namespace>
<optionName>AWS_CONFIG_BUCKET_NAME</optionName>
<value>${aws.App.configurationBucketName}</value>
</setting>
</optionSettings>
</configuration>
<executions>
<execution>
<phase>deploy</phase>
<goals>
<goal>describe-environments</goal>
<goal>upload-source-bundle</goal>
<goal>create-application-version</goal>
<goal>update-environment</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<plugins>
<plugin>
<groupId>br.com.ingenieux</groupId>
<artifactId>beanstalk-maven-plugin</artifactId>
<version>1.4.0</version>
<configuration>
<region>ap-southeast-2</region>
<environmentName>${aws.enviornmentName}</environmentName>
<cnamePrefix>${aws.cNamePrefix}</cnamePrefix>
<applicationName>${aws.applicationName}</applicationName>
<environmentRef>${aws.enviornmentRef}</environmentRef>
<solutionStack>${aws.solutionStack}</solutionStack>
<useStagingDirectory>true</useStagingDirectory>
<s3Bucket>${aws.s3.bucket.ReleaseLocation}</s3Bucket>
<verbose>true</verbose>
<s3Key>
${project.artifactId}/${project.build.finalName}-${maven.build.timestamp}.war
</s3Key>
<optionSettings>
<setting>
<namespace>aws:elasticbeanstalk:application</namespace>
<optionName>Application Healthcheck URL</optionName>
<value>/</value>
</setting>
<setting>
<namespace>aws:elasticbeanstalk:environment</namespace>
<optionName>EnvironmentType</optionName>
<value>${aws.EnvironmentType}</value>
</setting>
<setting>
<namespace>aws:autoscaling:launchconfiguration</namespace>
<optionName>InstanceType</optionName>
<value>${aws.instanceType}</value>
</setting>
<setting>
<namespace>aws:elasticbeanstalk:application:environment</namespace>
<optionName>AWS_ACCESS_KEY_ID</optionName>
<value>${aws.accessKeyId}</value>
</setting>
<setting>
<namespace>aws:elasticbeanstalk:application:environment</namespace>
<optionName>AWS_SECRET_KEY</optionName>
<value>${aws.secretKey}</value>
</setting>
<setting>
<namespace>aws:elasticbeanstalk:application:environment</namespace>
<optionName>AWS_CONFIG_BUCKET_NAME</optionName>
<value>${aws.App.configurationBucketName}</value>
</setting>
</optionSettings>
</configuration>
<executions>
<execution>
<phase>deploy</phase>
<goals>
<goal>describe-environments</goal>
<goal>upload-source-bundle</goal>
<goal>create-application-version</goal>
<goal>update-environment</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Comments
Post a Comment