Running AWS CLI

The final step is to add environment variables in our course in order to store user credentials and log into AWS CLI.

Terminal

Since our main means of interaction with AWS is the CLI, we can use the Terminal widget to achieve this interface.

Try running aws configure in the Terminal below:

Terminal 1
Terminal
Loading...

The AWS CLI is up and running, however, it asks us for our credentials each time.

To avoid this redundancy, we will use environment variables to store user credentials only once.

Environment Variables

In the Docker Container section of the course editor page, clicking the globe icon allows you to add environment variables in your course:

These variables will be available in any coding playground/terminal present in the course.

Let’s create three variables corresponding to the Access Key ID, Secret Access Key, and Region:

The Value of each Key has been left empty as these will be provided by the user.

Selecting Env Vars in the Terminal

Now, you can select which environment variables are required in a Terminal widget:

We’ve selected all three variables in our Terminal. To use the values provided by a user, we will add the following commands in the Start Script of our Terminal:

Press + to interact
aws configure set default.region $region && \
aws configure set aws_access_key_id $access_key_id && \
aws configure set aws_secret_access_key $secret_access_key && \
aws configure set default.output json

The $ notation is used to access environment variables. The command in line 4, aws configure set default.output json sets the output format to JSON. We do not need to provide an env variable for this value. You could also hardcode the region parameter of aws configure without providing the value as an env variable.

AWS CLI in Action

With all our configurations in place, it’s time to run the container. Enter your AWS credentials below and launch the Terminal.

Terminal 1
Terminal
Loading...

Users can now work with whatever services they have on their AWS accounts.


That marks the end of this tutorial! We’ve examined the basic setup required to run AWS on the Educative platform. Feel free to make additions to the Dockerfile according to your needs.