Connect to AWS

You can connect to AWS by performing the following steps:

  1. Create Environment Variables.
  2. Get AWS Caller Information.
  3. Install boto and boto3.

Prerequisites#

Before you connect to AWS, you’ll need the following:

  • Active AWS account
  • Access Key
  • Secret Access Key for an existing IAM user in the AWS account

If you do not have the account and keys setup, you can do so by following the links below:

Admin Policy
The user must have the AdministratorAccess or SystemAdministrator policy assigned to it.

Create environment variables#

Ansible uses AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY to authenticate to AWS.

Once you have acquired the keys, you can create the environment variable with the export command within the container.

Docker Setup
We have pre-configured the environment to save you the hassle of rebuilding and re-running your containers. All the commands will work on your local setup as well.

Run the following commands in the Ansible environment:

Create AWS environment variables

Create AWS caller information#

You can verify that connection to AWS is established by gathering the caller information using the Ansible module aws_caller_info.

Run the following command in the Ansible environment:

Use Ansible to get AWS caller information

Running the aws_caller_info again will return the JSON object back.

Practice all the commands one by one in the Ansible environment. We can skip the first two commands by setting the environment variables in the terminal. You can find the summarized view of all the commands below:

Commands to connect to AWS
This code requires the following environment variables to execute:
AWS_ACCESS_KEY_ID
Not Specified...
AWS_SECRET_ACCESS_KEY
Not Specified...
Terminal 1
Terminal

Click to Connect...

Troubleshooting tips#

Missing boto3 package
You might come across the following message.
Failed to import the required Python library (botocore or boto3) on 022cdb1cb53c Python /usr/bin/python2. Please read the module documentation and install it in the appropriate location. If the required library is installed, but Ansible uses the wrong Python interpreter, please consult the documentation on ansible_python_interpreter.”

Install boto3#

The error states that it “failed to import the library botocore or boto3”. You can resolve this issue by installing the package boto3. Run the following command in the Ansible environment:

Use pip3 to install boto3

Install boto#

Some Ansible modules depend on the boto package. You can install it by using the command:

Use pip3 to install boto

Update Dockerfile#

You made some changes inside your container. If that container is deleted, all the changes will be lost. You can save your changes by updating the Dockerfile and rebuilding the image.

Review the code’s highlighted lines for the newly introduced changes, i.e., line 9-10. You can review the updated Dockerfile below:

Dockerfile

In this lesson, we covered how to export your access keys for AWS, use the aws_caller_info to verify the connection, and install missing packages.

Introduction
Connect to Azure
Mark as Completed
Report an Issue