Codespaces With AWS

I’ve been going through the excellent AppSync Masterclass by Yan Cui. During the course I wanted to give GitHub Codespaces a try.

While Codespaces will correctly start a container with the the required node tools it doesn’t have the AWS cli which is needed for deployments from the Serverless framework. It tuns out the fix is quite simple and the Github documenation covers a lot of what you need.

The main part of it is you need to create a .devcontainer folder in your repo. Inside this folder you need a Docker file and a devcontainer.json file (Notice there is no . in the file name only in the folder name). Github has a repo with the base conatiners for the language you are using.

I used the Node container and created this Dockerfile.

1
2
3
4
5
6
ARG VARIANT=16
FROM mcr.microsoft.com/vscode/devcontainers/javascript-node:${VARIANT}

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

The devcontainer.json just contains

1
2
3
4
5
6
7
8
{
"name": "Node.js",
"build": {
"dockerfile": "Dockerfile",
// Update 'VARIANT' to pick a Node version: 12, 14, 16
"args": { "VARIANT": "16" }
}
}

Which is just copied from the GitHub template.

The next bit was I didn’t really want to store my credenitals in the container and GitHub and thought of that. I created to variables AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY with my credentials from AWS.
CodeSpaces secrets

The last thing was rebuilding the CodeSpace and Restarting it, both of wich you do in VSCode from the command pallet.
Rebuild

After that try the aws cli.
AWS Cli