如何使用AWS CLI 2将更新后的JAR文件上传到现有的Java Elastic Beanstalk实例?

huangapple go评论81阅读模式
英文:

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

问题

我通过 Web UI 手动设置了一个 Java Elastic Beanstalk 实例。

我随时可以通过 UI 手动上传更新后的 JAR 文件。

如何通过 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?

答案1

得分: 0

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.

英文:

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.

答案2

得分: -1

你可以分为两个步骤来完成:

  1. 使用create-application-version创建新的应用程序版本,使用你的新程序。请注意要使用的版本的 --version-label
  2. 使用update-environment更新你的 EB 环境,使用新的应用程序版本。你需要提供来自步骤 1 的 --version-label

或者,你可以使用由AWS专门开发用于EB的AWS EB CLI,这是一个命令行工具。

英文:

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.

huangapple
  • 本文由 发表于 2020年9月16日 05:21:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/63910008.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定