简体   繁体   English

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

[英]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.我有一个通过 Web UI 手动设置的 Java Elastic Beanstalk 实例。

I can upload an updated JAR to it any time manually through the UI.我可以随时通过 UI 手动上传更新的 JAR。

How do I accomplish the same via the AWS CLI 2?如何通过 AWS CLI 2 完成相同的操作?

I use maven to build my JAR.我使用 maven 来构建我的 JAR。

mvn clean install

This generates the JAR my-app.jar in the ./target directory.my-app.jar./target目录中生成 JAR my-app.jar

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步骤 1. 将 JAR 上传到 S3 存储桶

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.步骤 2. 在 Elastic Beanstalk 中创建应用程序的一个版本。

This references the JAR uploaded to S3 in Step 1.这引用了在步骤 1 中上传到 S3 的 JAR。

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步骤 3. 在 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. a) 您不部署 JAR。 You deploy a Version.您部署一个版本。 And the Version points to the JAR.而版本指向 JAR。 This is distinct from (what you see) what you do through the UI, where you just upload the JAR and it gets deployed.这不同于(您看到的)您通过 UI 执行的操作,在 UI 中您只需上传 JAR 并进行部署。

b) The source-bundle of the Version points to the JAR. b) 版本的source-bundle指向 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是的,虽然在 Java 世界中,“源”这个词意味着某些东西,而 JAR 不是源,但在 Elastic Beanstalk 世界中,“源”是您的可执行代码

c) the JAR the Version points to has to be in S3. c) Version 指向的 JAR 必须在 S3 中。 That is where you upload your JAR.是您上传 JAR 的地方。

You do it in two sets :分两组进行

  1. Create new application version with your new program using create-application-version .使用create-application-version使用您的新程序创建新的应用程序版本 Note the --version-label for the version that you want to use.请注意您要使用的版本的--version-label
  2. Update your EB environment to use the new application version with update-environment .通过update-environment更新您的 EB 环境以使用新的应用程序版本。 You will have to provide --version-label from step 1.您必须提供步骤 1 中的--version-label

Alternatively, you can use AWS EB CLI which is CLI tool specifically developed by AWS for EB.或者,您可以使用AWS EB CLI ,它是 AWS 专门为 EB 开发的 CLI 工具。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从Spring Java Elastic Beanstalk应用程序连接到我的AWS DynamoDB实例? - How do I connect to my AWS DynamoDB instance from a Spring Java Elastic Beanstalk app? 将现有的 java WAR 文件上传到 AWS Elastic Beanstalk - Upload existing java WAR file to AWS Elastic Beanstalk Elastic Beanstalk CLI部署jar - Elastic Beanstalk CLI deploy jar 部署到AWS Elastic Beanstalk后如何访问servlet? - How do I access servlets after deploying to AWS Elastic Beanstalk? 如何在AWS Elastic Beanstalk环境中配置负载均衡器? - How do I configure a load balancer in an AWS Elastic Beanstalk environment? 使用 Spring WebSecurityConfigurerAdapter 时,如何让我的 Elastic Beanstalk 实例保持健康? - How do I keep my Elastic Beanstalk instance healthy when using Spring WebSecurityConfigurerAdapter? 在aws弹性beantalk上上传文件? - upload files on aws elastic beanstalk? 如何使用Elastic Beanstalk和Java使用cron作业? - How do you use cron jobs using Elastic Beanstalk and Java? 如何从AWS Elastic Beanstalk连接到Google Cloud SQL实例 - How to connect to a google cloud sql instance from AWS elastic beanstalk 结合使用AWS Elastic Beanstalk和Java / BlazeDS / Spring应用程序 - Using AWS Elastic Beanstalk with a Java/BlazeDS/Spring application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM