14

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 :)

Aditya Anand
  • 776
  • 2
  • 9
  • 29
  • curious why you don't want to manage the entire lifecycle through EB cli as part of `eb deploy` :) .. can you please elaborate your requirements ? (As far as I know, app versions can be uploaded manually only via console) – akskap Feb 09 '20 at 20:04
  • I have a custom artefact generation process, bundling multiple JARs from several sub modules into one which eb deploy does not support – Aditya Anand Feb 10 '20 at 03:48
  • ok, and placing the dependent jars as part of the code repository won't work here ? This is something which then goes in the CI/CD scripts before you run `eb deploy`. You might want to check `.ebignore` file to make sure that the CLI does not ignore the additional jars. Later in the deployment process, you can then use the lifecycle hooks provided by Beanstalk like `commands:` and `container_commands:` (depending on a docker/non-docker based environment) to do custom-magic before the application comes up – akskap Feb 10 '20 at 09:26

2 Answers2

26

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
Samkit Jain
  • 1,560
  • 2
  • 16
  • 33
  • 1
    That did it for me. Struggled before with the EB-CLI to define a archive file. – xoned Jan 15 '21 at 23:12
  • nice, but how to do it without a public s3 bucket? public bucket with source IP is a problem. – bjm88 Jan 26 '21 at 03:10
  • @bjm88 The S3 bucket does not need to be public. Just ensure that the right access/permissions are set up. For example, the IAM user/role doing the `cp` command must have the `s3:PutObject` permission for the `mybucket` resource. – Samkit Jain Jan 26 '21 at 10:36
9

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!