简体   繁体   中英

How do I upload an updated JAR to an existing Java Elastic Beanstalk instance using the AWS CLI 2?

I have a Java Elastic Beanstalk instance set up manually through the web UI.

I can upload an updated JAR to it any time manually through the UI.

How do I accomplish the same via the AWS CLI 2?

I use maven to build my JAR.

mvn clean install

This generates the JAR my-app.jar in the ./target directory.

I then do the following

export version=1.0-`date +"%Y%m%d-%H%M%S"`

This is an environment variable I'll use throughout the process.

Step 1. Upload the JAR to an S3 bucket

aws s3 cp ./target/my-app.jar s3://my-app.foo.bar/my-app-${version}.jar

Step 2. Create a Version of the Application in Elastic Beanstalk.

This references the JAR uploaded to S3 in Step 1.

aws elasticbeanstalk create-application-version \
  --application-name my-app \
  --version-label ${version} \
  --source-bundle S3Bucket="my-app.foo.bar",S3Key="my-app-${version}.jar"

Step 3. Deploy the Version in Elastic Beanstalk

aws elasticbeanstalk update-environment \
  --application-name my-app \
  --environment-name MyApp-env \
  --version-label ${version}

The key points to note here are that;

a) You don't deploy a JAR. You deploy a Version. And the Version points to the JAR. This is distinct from (what you see) what you do through the UI, where you just upload the JAR and it gets deployed.

b) The source-bundle of the Version points to the JAR. Yes, although in the Java world, the word 'source' means something and a JAR is not source, in the Elastic Beanstalk world, the 'source' is your executable code

c) the JAR the Version points to has to be in S3. That is where you upload your JAR.

You do it in two sets :

  1. Create new application version with your new program using create-application-version . Note the --version-label for the version that you want to use.
  2. Update your EB environment to use the new application version with update-environment . You will have to provide --version-label from step 1.

Alternatively, you can use AWS EB CLI which is CLI tool specifically developed by AWS for EB.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM