AWS Logo
Menu

Contributing to aws-cdk using a Dev Container

Writing PRs with VSCode in a Dev Container

Pahud Hsieh
Amazon Employee
Published Oct 9, 2024
Last Modified Oct 10, 2024
In the previous article, we talked about Contributing to AWS CDK. A common question is how to develop pull requests (PRs) using a dev container.
A dev container is a Docker-based environment used to create a consistent and isolated development setup. It allows you to define the tools, runtime, and settings required for development in a container, which can be shared across teams or contributors. Using dev containers helps ensure that everyone is working in the same environment, reducing compatibility issues. This is especially useful for open-source projects or when working across different machines.
For example, in Visual Studio Code, you can use the Remote - Containers extension to configure a dev container, typically defined using a .devcontainer folder containing Docker configuration files. This setup makes it easier to run and test your pull requests (PRs) in an environment that matches your production or staging environment.
In AWS CDK, the dev container configuration is defined in .devcontainer/devcontainer.json, which essentially builds a container image from the Dockerfile. But what if you just need a dev container using the official recommended configuration from devcontainers?

My Dev Container Sample

Open the AWS CDK repository in VS Code, edit the .devcontainer/devcontainer.json file, and replace its content with the following.
Press Shift + Command + P to open the command palette, search for Dev Containers: Rebuild Container, and select it. VS Code will then rebuild the container using the specified image. Once done, yarn install will run automatically via the postCreateCommand. Afterward, execute the following commands to set up the environment:
That's it! Enjoy!
 

Any opinions in this post are those of the individual author and may not reflect the opinions of AWS.

Comments