So, I have the AWS Developer Associate exam booked in a week’s time, so I’m going through all the services the questions about which are likely to come up in the exam. Yesterday I looked at Elastic Beanstalk, an AWS service that lets you quickly deploy application with things such as load balancing, autoscaling and monitoring taken care of.
Elastic Beanstalk CLI is powered by Python, so you need to install that first. After that, you run the following in your command line:
pip install awsebcli --upgrade --user
You also need to configure the AWS CLI by running
I didn’t have time to write an application to deploy so I stole a sample one from the AWS website. Here you can find a lot of sample apps in various languages that are used to launch Elastic Beanstalk applications. I downloaded the one in Python (as it is the next language I’m aiming to learn). Now you just need to go into the folder with the source code via the command line, and we’re good to start with the Elastic Beanstalk CLI.
eb init. This command sets some defaults for your application; it asks you some questions about the region into which you’d like to deploy the app, if you need to set up SSH for your servers and so on. If you don’t specify the name of the app, the default will be ElasticBeanstalk. Otherwise you add the name to the command
eb init MyTestApp
eb create MyTestApp-dev. This command creates your environment and deploys your app into it.
eb open MyTestApp-devopens the app in the browser. That’s quite handy because you don’t have to go to the console to get the link
eb list. This command lists your environments
eb deploy MyTestApp-devuploads a new version of the app after a change. You can also label the version like so:
eb deploy MyTestApp-dev -l v1.1 -m“deployed on 28 Jan 2021”. where -l flag is for version, and -m is for a message.
- To create another environment off using a specific version of the app you use
eb create MyTestApp-uat --version v1.1
eb use MyTestApp-uatcommand is used to set the default environment.
- Monitoring can be done by using these commands:
eb health. If no environment name is passed, it will use the default environment.
- If you have some environment specific variables that you would like to set, you can use the following command:
eb setenv -e MyTestApp-dev var1=Oksana var2=Horlock. And to view the value of the variables you can use
eb printenv MyTestApp-dev.
10. Finally, to nuke everything you’ve created for the application, run
eb terminate --all.
There is also an AWS CLI for Elastic Beanstalk. Here the difference is that with these commands there are no defaults like we have seen above, and you have to pass in the some parameters. For example, if you want to create an application, you run
aws elasticbeanstalk create-application --application-name MyTestApp
It also looks like the EB CLI is best suited for developers when they can actually see the application code, and the AWS CLI is preferrable to use in scripts or automation tasks.