Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploy war from S3 to AWS Elastic Beanstalk

I have 2 AWS machines, 1.dev (ec2) 2. prod (elastic beanstalk). I build and deploy on dev (machine1) after every commit which results into a war file (which will also be uploaded on an S3 bucket using s3cmd tool). Then I test the newly deployed war on dev machine, if it seems fine, then I download the war from dev(ec2) and then upload it to the prod machine (Elastic beanstalk).

Is there a way to make elastic beanstalk to take the war directly from the S3 bucket, rather than downloading it from ec2 and then uploading it to elastic beanstalk?

I tried creating new environment and then gave s3 bucket path for application version, but it din't work. (gave some error saying "this can only be done in VPC").

like image 422
thekosmix Avatar asked Sep 05 '14 10:09

thekosmix


People also ask

Can we use S3 with Elastic Beanstalk?

To access an S3 bucket from Elastic Beanstalk, verify that your AWS Identity and Access Management (IAM) instance profile is attached to an Amazon Elastic Compute Cloud (Amazon EC2) instance. The instance must have the correct permissions for Amazon S3.

How do I deploy a WAR file in AWS?

Download and Install Tomcat. Configure the server. xml, tomcat-users and set the username, password and port. Once done, you can place your war file in the /webapps folder. or Open your instance's Public IP in url.


2 Answers

I have got the best answer in this post :

it requires 3 simple steps using AWS CLI:

  1. Upload to S3 bucket: aws s3 cp /var/lib/tomcat7/webapps/ROOT.war s3://elasticbeanstalk-ap-southeast-1-xxxxxx/myROOT.war
  2. Create application version: aws elasticbeanstalk create-application-version --application-name your_app_name --version-label your_version_label --source-bundle S3Bucket=elasticbeanstalk-ap-southeast-1-xxxxxx,S3Key=myROOT.war
  3. Update your environment: aws elasticbeanstalk update-environment --environment-name your_environment_name --version-label your_version_label

I have created a bash script, which takes just 3 seconds for all the above steps. Do go through the link for more descriptive answer.

like image 124
thekosmix Avatar answered Sep 22 '22 13:09

thekosmix


If your s3 war file is in mybucket/test/myapp.war then creating an application version with the s3 bucket as mybucket and test/myapp.war is the way to do it. Not sure why you are getting the VPC related error. When and where do you see that error? When you create an application version or when you create an environment? Does the API call throw the error message immediately do you see that in the events later?

like image 43
Rohit Banga Avatar answered Sep 22 '22 13:09

Rohit Banga