Using Docker for AWS CDK development
Have a consistent development environment for your team on any OS
In early 2022, I was starting a new project on AWS. I was using AWS CDK for about one year at this time. In a previous project, the team members used a mix of macOS and Linux computers. It was only a matter of time before a Windows user joined the team. Having a consistent development environment was beneficial. Based on previous experiments with Docker, I decided to use a Docker container as that development environment.
Stop Installing Node.js and Global Npm Packages, Use Docker Instead
Protect your system from vulnerabilities
About one year later, in early 2023, I worked on a different CDK project. I started the project using macOS. About one month later, the team leader gave me a Windows laptop for me to use going forward. It was super simple to move my development environment. I installed Docker and git, cloned the git repository, ran the Docker command, and I was able to start developing right away. Using Docker containers saved me a lot of time.
Here is how I set up my Docker container
In my git repository, I created a
docker-compose.yml file where I added the following code:
# used for local development
In the terminal, I ran the following command to start the container.
docker compose run --rm nodejs
Now I have a terminal running within the container.
I go to my AWS CDK app folder.
I paste my AWS credentials into the terminal. I can now run typical CDK commands.
npm run cdk synth
npm run cdk deploy
# or however you have your cdk command execution set up
The setup was pretty simple. Now we have a consistent development environment regardless of the operating system. Leave a comment and let me know your experience.
Before you go
Here are other posts you might enjoy.