20

In the documentation it states that the EB CLI is replaced by AWS CLI but all of the documentation is still talking about EB CLI.

I have created an application in Elastic Beanstalk console and now I'm ready to start developing. I have all the tools installed on Ubuntu and I've already tested it locally. Now I want to deploy it to Elastic Beanstalk. How do I do this with AWS CLI?

MikkoP
  • 4,864
  • 16
  • 58
  • 106

2 Answers2

42

You have to create a source bundle from your application, see details here: http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/applications-sourcebundle.html (Or alternatively you can use AWS CodeCommit or AWS CodeBuild as source for your application.)

Then you can use the AWS CLI to create a new version from your application and deploy it to one application environment. (See the CLI documentation for EBS here.)


Create a source bundle:

zip MyCodeBundle.zip <source files>

Upload that to S3:

aws s3 cp MyCodeBundle.zip s3://a-bucket-where-you-store-your-source-bundles/

Create a new application version using the source bundle you just uploaded:

aws elasticbeanstalk create-application-version --application-name YourEBSAppName --version-label YourVersionLabel --source-bundle S3Bucket="a-bucket-where-you-store-your-source-bundles",S3Key="MyCodeBundle.zip"

And finally you update one of your environments to use that version (this is deploy even though that verb is completely missing from the new AWS CLI for EBS - this was a little confusing for me):

aws elasticbeanstalk update-environment --application-name YourEBSAppName --environment-name YourEBSEnvironmentName --version-label YourVersionLabel
qqbenq
  • 10,220
  • 4
  • 40
  • 45
  • 2
    Thanks! I was looking for a way to deploy to EB without the weird git integration stuff Amazon provides. This is a bit longer than I hoped, but it works. – Laurence Gonsalves Apr 13 '18 at 20:14
  • If you are trying to run this through Github actions, you need to add region flag. "--region us-east-1" – alext Jun 11 '20 at 08:15
  • Can you pls help me with this - How would I know if the environment deployment is completed? since even after aws elasticbeanstalk update-environment is success- deployment is still being processed in aws – krishna422 Oct 19 '21 at 11:54
  • I got this error with **create-application-version** command `An error occurred (InvalidParameterValue) when calling the CreateApplicationVersion operation: No Application named 'hello-world' found. ` – JRichardsz Feb 14 '22 at 22:40
  • Also, currently **create-application-version** don't create the environment – JRichardsz Feb 14 '22 at 22:52
2

To complement @qqbenq answer, here is an example of AWS CLI deployment to beanstalk with a given deployment policy:

aws elasticbeanstalk update-environment \
    --environment-name <eb-env-name> \
    --version-label <verion-label-to-deploy> \
    --option-settings \
        Namespace=aws:elasticbeanstalk:command,OptionName=DeploymentPolicy,Value=Rolling \
        Namespace=aws:elasticbeanstalk:command,OptionName=BatchSizeType,Value=Fixed \
        Namespace=aws:elasticbeanstalk:command,OptionName=BatchSize,Value=1
Marcin
  • 215,873
  • 14
  • 235
  • 294
  • 1
    This really saved my day, all I was looking for was to update one `custom value` inside configuration. This was my final command: `aws elasticbeanstalk update-environment --environment-name myenvname --option-settings Namespace=aws:elasticbeanstalk:application:environment,OptionName=CONFIGURATION_NUMBER,Value=1.2.003` – mdabdullah Dec 02 '20 at 07:03
  • @mdabdullah Glad the answer was useful:-) – Marcin Dec 02 '20 at 07:20