Posts Getting started with the Elastic Beanstalk CLI
Post
Cancel

Getting started with the Elastic Beanstalk CLI

The Elastic Beanstalk service is the closest there is to an out-of-the-box hosting solution on AWS. However, it is not nearly as easy as launching an application on a platform like Heroku. Assuming that you have already created an application and environment on Elastic Beanstalk through the console, we will walk through configuring the Elastic Beanstalk command-line interface (CLI) to deploy your application code.

Overview

  1. Install the Elastic Beanstalk CLI.
  2. Initialize an existing application to use the CLI.
  3. Deploy an application.
  4. Locate the CLI configuration files for future credential updates.

Assumptions

  1. You have an IAM user account that has sufficient privileges for Elastic Beanstalk and EC2 and you have received a set of programmatic keys (aws_access_key_id and aws_secret_access_key).
  2. You have created an application and environment through the Elastic Beanstalk console to which you are ready to deploy.

Installing the EB CLI

There are several methods to install the Elastic Beanstalk CLI. Despite the AWS documentation recommendation to use setup scripts, I have never been successful with them and prefer to use the pip installation method instead. Use whatever method works best for your platform, and confirm that the CLI has been successfully installed by running the command for the version:

1
2
$ eb --version
EB CLI 3.19.2 (Python 3.9.0)

Initialize your application to use the CLI

In the root of your application, initialize the CLI by running the init command. The -i flag is for the “interactive” mode. While it is not necessary to supply this flag the very first time you run the initialization, you must supply it if you ever wish to re-initialize your application and change any values. The CLI will create a profile for your application in its configuration files with the default name of eb-cli. You can customize this name during initialization by supplying a name to the --profile flag. Having a custom name will help you identify your credentials in the configuration file that the CLI creates. This is particularly helpful if you have multiple projects.

1
$ eb init -i --profile=my-application

Follow the prompts, selecting the default region, existing application that you defined through the Elastic Beanstalk console, platform, etc. You will be asked to supply the aws_access_key_id and aws_secret_access_key.

When you are asked to set up SSH for your instance, select “Y” if you have not already set up a key pair. Make sure to give the key pair a name that identifies it as belonging to you, in case you have multiple developers who have access to your application on Elastic Beanstalk. If you have already set up a key pair, then it is okay to select “n”.

Deploy your application

You are now ready to deploy your application. In the root of your app, run the deploy command and supply the name of the environment to which you are deploying. For example, if you created an environment called “staging” and would like to deploy your code there, then run:

1
2
3
4
5
6
7
$ eb deploy staging
Creating application version archive "app-20452-201208_123456".
Uploading my-application/app-20452-201208_123456.zip to S3. This may take a while.
Upload Complete.
2020-12-08 20:04:17    INFO    Environment update is starting.
2020-12-08 20:04:22    INFO    Deploying new version to instance(s).
...

After the application is finished deploying, take a look at the application versions in the Elastic Beanstalk console. From the Elastic Beanstalk services page, select “Applications” in the navigation, and then select the name of your application. In the navigation links, you should now see a link called “Application versions”. Click this to see all the versions you have uploaded and the environments to which they are deployed. Supposing you also have an environment called “production”, you can deploy this version to your production environment directly through the console, or you can use the CLI and supply the version number:

1
$ eb deploy production --version=app-20452-201208_123456

CLI configuration files

When you initialize your first project with the EB CLI, it will create a new configuration file in your home directory:

1
2
3
4
$ cat ~/.aws/config
[profile my-application]
aws_access_key_id = AKIABCDEFJ123456ZYX
aws_secret_access_key = abcdEFJHIJ1234556890abcdeFGHIjklmnoPQR123

If you didn’t supply a value for --profile then your credentials will be listed under the default eb-cli profile name. If you ever need to update your credentials, you can edit this file and insert the new credentials under the appropriate profile. You can see which profile is associated with your project by viewing the .elasticbeanstalk/config.yml file in the root of your application.

References

See the full list of EB CLI commands as part of the AWS documentation.

This post is licensed under CC BY 4.0 by the author.
Contents

Was this post helpful? Get Rails, AWS cloud deployment and other software development tips delivered right to your Inbox.

* indicates required

Install FFmpeg on Elastic Beanstalk

-

Comments powered by Disqus.