I am currently working on a SAM project using template.yml
. Here is a snippet of the configuration:
Globals:
Function:
Timeout: 30
Environment:
Variables:
DBNAME: !Ref DBNAME
Resources:
MessageFunction:
Type: AWS::Serverless::Function
Properties:
PackageType: Image
Architectures:
- x86_64
Events:
Message:
Type: Api
Properties:
Path: /message
Method: post
Metadata:
Dockerfile: Dockerfile.message
DockerContext: ./botapp
DockerTag: python3.9-v1
To deploy this configuration, use the following command:
sam deploy --guided --parameter-overrides DBNAME=mydb
This will set the environment variable DBNAME=mydb
and build the image from Dockerfile.message
.
The process works well at the moment.
However, I now want to migrate this setup to CDK.
In my initial attempt with CDK, I wrote this code:
const messageLambda = new lambda.DockerImageFunction(this, "BotLambda", {
code: lambda.DockerImageCode.fromImageAsset("chatbot-sam/botapp"),
});
But I need to specify the dockerfile
and environment variables
.
For example:
const messageLambda = new lambda.DockerImageFunction(this, "BotLambda", {
code: lambda.DockerImageCode.fromImageAsset(
"chatbot-sam/botapp",
dockerfile: Dockerfile.message,
environment_variables: { DBNAME:'mydb'}
),
});
Although the above code is not correct, is my idea clear?
How can I configure the Dockerfile
and environment variables
in CDK?