Running a CDK/SAM Lambda function locally on Docker

Structure

  • stack - contains cdk-defined cloud infrastructure to work with the lambda
  • lambda - contains the lambda function itself

Prerequisites

Install docker, aws-cli, cdk, and sam.

Commands

Run Lambda locally

1. compile the code

./gradlew clean build

2. synthesize the stack

cd stack && cdk synth --no-staging

3. runs the lambda locally

cd stack && sam local invoke KotlinFun --no-event -t cdk.out/Stack.template.json

Deploy the lambda to AWS

1. build the solution

gradle clean build

2. synthesize the stack

cd stack && cdk synth

3. bootstrap AWS resources needed by CDK

cdk bootstrap

4. deploy the stack

cdk deploy