Create AWS-CDK image container

Create AWS-CDK image container


5 min read

Create AWS-CDK image container

⚛️ 📄 🚀

All CDK developers need to install Node.js 10.3.0 or later, even those working in languages other than TypeScript or JavaScript such as python

Important Node.js versions 13.0.0 through 13.6.0 are not compatible with the AWS CDK.

How to create AWS-CDK image container from amazon/aws-lambda-python (or any python base images) and install nodejs 12

What’s In This Document

🚀 Dockerfile

  • Base image: amazon/aws-lambda-python:3.8
  • Install nodejs 12 and aws-cdk version 1.73.0
  • Install some cdk libaries
FROM amazon/aws-lambda-python:3.8


WORKDIR /opt/stack

RUN yum -y update && \
    curl -sL | bash - && \
    yum list available nodejs && \
    yum install -y python3-pip && \
    yum install -y nodejs && \
    npm install -g aws-cdk@${AWS_CDK_VERSION} && \
    pip3 install aws-cdk.core

CMD ["cdk version"]

🚀 Build and Test container image

⚡ $ docker build -t awscdk .
⚡ $ docker run -d --name test -it awscdk
⚡ $ docker exec test cdk version
1.73.0 (build eb6f3a9)
⚡ $ docker exec test node --version
⚡ $ docker exec test npm --version
⚡ $ docker exec test cdk init -l python
Applying project template app for python

# Welcome to your CDK Python project!

This is a blank project for Python development with CDK.

The `cdk.json` file tells the CDK Toolkit how to execute your app.

This project is set up like a standard Python project.  The initialization
process also creates a virtualenv within this project, stored under the `.venv`
directory.  To create the virtualenv it assumes that there is a `python3`
(or `python` for Windows) executable in your path with access to the `venv`
package. If for any reason the automatic creation of the virtualenv fails,
you can create the virtualenv manually.

To manually create a virtualenv on MacOS and Linux:


Initializing a new git repository...
/bin/sh: git: command not found
Unable to initialize git repository for your project.
Please run 'python3 -m venv .venv'!
Executing Creating virtualenv...
✅ All done!

⚡ $ docker exec -it test ls  cdk.json  requirements.txt  source.bat  stack

⚡ $ docker exec -it test ls stack


Read More

:stars: Blog · Web · Linkedin · Group · Page · Twitter :stars: