We will resolve the issues that still exist with our application shortly, but in order do so we are going to use the Elastic Beanstalk CLI to continue configuring our application and address these issues.
Before we start using the Elastic Beanstalk CLI, it is important to understand that the current version of this application does have some challenges when interacting with the multi-factor authentication (MFA) requirements we introduced for all console and API access in earlier chapters. If you continue to use MFA, you will notice that you are prompted each and every time you execute an Elastic Beanstalk CLI command.
To work around this, we can temporarily remove the MFA requirement by first removing your user from the Users group:
> aws iam remove-user-from-group --user-name justin.menga --group-name Users
Next, comment out the mfa_serial line within the docker-in-aws profile inside your local ~/.aws/config file:
[profile docker-in-aws]
source_profile = docker-in-aws
role_arn = arn:aws:iam::385605022855:role/admin
role_session_name=justin.menga
region = us-east-1
# mfa_serial = arn:aws:iam::385605022855:mfa/justin.menga
Note, this is not ideal, and in a real world scenario you probably would not have the ability to, nor want to, temporarily disable MFA for a given user. Bear this in mind when considering Elastic Beanstalk, as you will generally rely on the Elastic Beanstalk CLI for a number of operations.
With MFA now temporarily disabled, you can install the Elastic Beanstalk CLI, which you can do by using the Python pip package manager. Once it's been installed, it will be accessible via the eb command:
> pip3 install awsebcli --user
Collecting awsebcli
...
...
Installing collected packages: awsebcli
Successfully installed awsebcli-3.14.2
> eb --version
EB CLI 3.14.2 (Python 3.6.5)
The next step is to initialize the CLI in the todobackend/eb folder that you created earlier:
todobackend/eb> eb init --profile docker-in-aws
Select a default region
1) us-east-1 : US East (N. Virginia)
2) us-west-1 : US West (N. California)
3) us-west-2 : US West (Oregon)
4) eu-west-1 : EU (Ireland)
5) eu-central-1 : EU (Frankfurt)
6) ap-south-1 : Asia Pacific (Mumbai)
7) ap-southeast-1 : Asia Pacific (Singapore)
8) ap-southeast-2 : Asia Pacific (Sydney)
9) ap-northeast-1 : Asia Pacific (Tokyo)
10) ap-northeast-2 : Asia Pacific (Seoul)
11) sa-east-1 : South America (Sao Paulo)
12) cn-north-1 : China (Beijing)
13) cn-northwest-1 : China (Ningxia)
14) us-east-2 : US East (Ohio)
15) ca-central-1 : Canada (Central)
16) eu-west-2 : EU (London)
17) eu-west-3 : EU (Paris)
(default is 3): 1
Select an application to use
1) todobackend
2) [ Create new Application ]
(default is 2): 1
Cannot setup CodeCommit because there is no Source Control setup, continuing with initialization
The eb init command uses the --profile flag to specify a local AWS profile, and then prompts for the region that you will be interacting with. The CLI then checks to see if there are any existing Elastic Beanstalk applications, and prompts you as to whether you want to manage an existing application or create a new application. Once you have made your selections, the CLI will add project information to the current folder under the a folder called .elasticbeanstalk, and will also create or append to a .gitignore file. Given our eb folder is a a subdirectory of the todobackend repository, it is a good idea to append the contents of the .gitignore file to the root of the todobackend repository:
todobackend-aws/eb> cat .gitignore >> ../.gitignore
todobackend-aws/eb> rm .gitignore
You can now use the CLI to view the current status of your application, list your application environments, and perform many other administrative tasks:
> eb status
Environment details for: Todobackend-env
Application name: todobackend
Region: us-east-1
Deployed Version: todobackend-source
Environment ID: e-amv5i5upx4
Platform: arn:aws:elasticbeanstalk:us-east-1::platform/multicontainer Docker running on 64bit Amazon Linux/2.11.0
Tier: WebServer-Standard-1.0
CNAME: Todobackend-env.p6z6jvd24y.us-east-1.elasticbeanstalk.com
Updated: 2018-07-14 23:23:28.931000+00:00
Status: Ready
Health: Red
> eb list
* Todobackend-env
> eb open
> eb logs
Retrieving logs...
============= i-0f636f261736facea ==============
-------------------------------------
/var/log/ecs/ecs-init.log
-------------------------------------
2018-07-14T22:41:24Z [INFO] pre-start
2018-07-14T22:41:25Z [INFO] start
2018-07-14T22:41:25Z [INFO] No existing agent container to remove.
2018-07-14T22:41:25Z [INFO] Starting Amazon Elastic Container Service Agent
-------------------------------------
/var/log/eb-ecs-mgr.log
-------------------------------------
2018-07-14T23:20:37Z "cpu": "0",
2018-07-14T23:20:37Z "containers": [
...
...
Notice that the eb status command lists the URL of your application in the CNAME property—take note of this URL as you will need it to test your application throughout this chapter. You can also use the eb open command to access your application, which will open the application URL in your default browser.