Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to upload and deploy zip file to AWS elastic beanstalk via CLI?

I do not want to use the console. No manual processes. I need a command line version, something that I can code in my continuous deployment scripts.

As part of the build process, I can output a ZIP file (be it on my local machine or in CI process, e.g: via bitbucket pipelines or AWS codedeploy VM instance).

I want a command like:

aws eb deploy my-app ./server.zip

That is, first upload my chosen zip file and then deploy it (doesn't have to be one command).

The official eb deploy does not seem to support this, nor have I been able to find any other method to do this.

Any ideas would be much appreciated :)

like image 938
Aditya Anand Avatar asked Feb 09 '20 17:02

Aditya Anand


People also ask

Which command is used to view the Elastic Beanstalk events that are using AWS CLI?

The EB CLI is a command line interface for AWS Elastic Beanstalk that provides interactive commands that simplify creating, updating and monitoring environments from a local repository. Use the EB CLI as part of your everyday development and testing cycle as an alternative to the Elastic Beanstalk console.

What kind of compressed file can be uploaded to deploy applications through Elastic Beanstalk?

When you use the AWS Elastic Beanstalk console to deploy a new application or an application version, you'll need to upload a source bundle. Your source bundle must meet the following requirements: Consist of a single ZIP file or WAR file (you can include multiple WAR files inside your ZIP file) Not exceed 512 MB.


2 Answers

I don't think eb CLI supports uploading a ZIP and updating an environment but you can use a combination of AWS CLI commands.

  1. Upload the ZIP to S3
  2. Create an application version
  3. Update the environment

Example,

aws s3 cp deploy.zip s3://mybucket/deploy.zip
aws elasticbeanstalk create-application-version --application-name my-app --version-label 12345 --source-bundle S3Bucket="mybucket",S3Key="deploy.zip"
aws elasticbeanstalk update-environment --application-name my-app --environment-name MyApp-env --version-label 12345
like image 156
Samkit Jain Avatar answered Oct 20 '22 13:10

Samkit Jain


I was looking for this answer as well. I was able to find some AWS documentation that lets you use the Elastic Beanstalk CLI configuration to upload the zip.

https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb-cli3-configuration.html#eb-cli3-artifact

Deploying an artifact instead of the project folder

You can tell the EB CLI to deploy a ZIP file or WAR file that you generate as part of a separate build process by adding the following lines to .elasticbeanstalk/config.yml in your project folder.

deploy:
 artifact: path/to/buildartifact.zip

If you configure the EB CLI in your Git repository, and you don't > commit the artifact to source, use the --staged option to deploy the latest build.

~/eb$ eb deploy --staged

I tested and it did work for me!

like image 40
giraffe-scarcity Avatar answered Oct 20 '22 12:10

giraffe-scarcity