bndkt

2021-10-07

Using AWS CLI within GitHub Codespaces

Mountains
Photograph by Nathan Dumlao

I really like coding with GitHub Codespaces, because they allow me to access the same development environment from virtually anywhere. Recently I was looking at using the AWS CLI within my Codespace and found it really easy to do so. Here are the few simple steps it takes:

GitHub Codespaces require a GitHub Organization account. In the organization account settings, find "Codespaces secrets" under Secrets > Codespaces. Here you can store encrypted environment variables that can be used within Codespaces.

Use AWS_DEFAULT_REGION, AWS_ACCESS_KEY_ID, and AWS_SECRET_ACCESS_KEY as names for the secrets.

Now to make the AWS CLI available within the terminal of your Codespace, edit the file .devcontainer/Dockerfile of your repository. If this file doesn't exist yet, you can use the "Add Development Container Configuration Files" option of VS Code.

Add the following lines to the Dockerfile to make the AWS CLI available within Codespaces:

RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" \
    && unzip awscliv2.zip \
    && sudo ./aws/install

After you edit the Dockerfile, Codespaces is offering to rebuild the container, which you should do. After that, AWS CLI will be available and thanks to the Codespaces Secrets we set up earlier, there's no need for further configuration.