Part 2 : DevOps — Automating Elastic Beanstalk environment creation using AWS Java SDK / CLI
In the previous blog, we saw how to deploy a stand-alone OpenAM instance in AWS using Elastic Beanstalk. In this blog, we are going to see on how to automate the entire infrastructure provisioning using AWS Java SDK as well as AWS CLI. This will be really useful when the infrastructure provisioning and deployment needs to be automated. These steps can be used to deploy any war file in tomcat.
Step 1 : Build the EBS Deployment package
Follow the same manual steps mentioned in previous blog. This can be easily automated using a build tool like Jenkins.
Step 2 : Upload the deployment package to AWS S3 bucket
Deployment package can be uploaded to s3 using below command. This can be automated using a shell script.
aws s3 cp ebspackage.zip s3://<bucket_name>
Step 3 : Create an environment in EBS to deploy OpenAM
This can be automated in multiple ways, either using AWS CLI commands or AWS SDK which is available in various programming languages like Java, Python etc.
Option 1 : AWS CLI
Let us first look at the AWS CLI commands to provision a Elastic Beanstalk environment and deploy OpenAM war. Below are the commands to automate all the manual steps mentioned in previous blog using AWS CLI. All these commands can be added as part of a shell script.
Option 2 : AWS Java SDK
Another option is to use AWS Java SDK to provision the same Elastic Beanstalk environment using infrastructure as code. Download / clone the GitHub project : https://github.com/awskarthik82/aws-openam/tree/master/openam-ebs and build the jar file using Maven from the root folder of this project. The command to build the jar file is :
mvn clean package
This should generate aws-ebs-openam-1.0.0.jar in target folder. Copy that jar file to lib folder and run either bin/awsopenam.bat or bin/awsopenam.sh depending on the OS. That should automatically provision the environment and deploy the OpenAM war file.
usage: awsopenam.bat <OPTIONS>
-a <arg> Elastic beanstalk application name
-b <arg> s3 bucket name where package is uploaded
-c <arg> Elastic beanstalk cname prefix
-e <arg> Elastic beanstalk environment name. For ex: test, dev
-h Help, show command line options
The entire logic to provision the environment and deploy war file is present in java class : https://github.com/awskarthik82/aws-openam/blob/master/openam-ebs/src/main/java/com/amazonaws/openam/DeployOpenAMEBS.java
This is a very basic program to provision the Elastic Beanstalk environment. The configuration can be customized according to project needs. But, the jar file needs to be rebuilt using Maven “mvn clean package” and copied to lib folder.
Step 4 : Configure OpenAM instance
Follow the same manual steps mentioned in previous blog. This can be automated using OpenAM ssoadm command or AMSTER.
Thank you for reading this article. If you have any questions / suggestions, kindly leave a comment.