Provisioning A Lambda function from a Container allows the establishment of a standardized Container-based build, and deployment, pipeline.
Lambda functions with large sets of dependencies will can be easier to package and deploy as a Container.
The Container Image is defined in app.py.
If use_pre_existing_image is True, then it is expected that a Container Image was created elsewhere and will be used by this CDK code and that the image_name is the ECR Repo name.
If use_pre_existing_image is False, then a new container will be created using the Dockerfile from the the lambda-image sub-directory.
After deploying the Lambda Function, go to the Lambda Dashboard, open the Lambda Function, and configure a test event.
After running the test event, the output should be from the Lambda Function code compiled in to the Container Image.
Deploy using CDK
Install CDK
cdk is a NodeJS app.
Install NodeJS.
Use npm to install cdk
sudo npm install -g --force cdk
Create Python Virtual Environment
python3 -m venv .venv
source .venv/bin/activate
Install Python-specific modules
Each service such as lambda(aws_cdk.aws_lambda) or ec2(aws_cdk.aws_ec2), has its own module which must be defined in requirements.txt.