AWS lambda api gateway deployment via AWS CDK

2022, Sep 19    


  • Linux environment( tested on MacOS M1 )
  • Python 3.8
  • CDK installed Instructions
  • Code for this reference example

Creating Virtual Environment for installing the Python dependencies

python3 -m venv .venv

Installing the Python dependencies

pip install -r requirements-dev.txt
pip install -r requirements.txt

requirements-dev.txt file contains the PyTest PyTest is being used for a simple Unit Test use case against our Infrastructure

Initialising the CDK environment

cdk bootstrap

Preview the preview of the compiled Cloudformation template ( baed on Python code)

cdk synth

Run PyTest tests

Run unit tests in tests/unit/ file :


This checks if API Gateway Method exists in compiled Cloudformation template & Lambda has Function name OrderGet and runtime of python 3.8

Deploy the stack to your AWS account

cdk deploy

After deployment you will see the Outputs section :

  Deployment time: 43.47s
cdk-multienv.orderapiEndpointE2C47C71 =

In this output, the value of “cdk-multienv.orderapiEndpointE2C47C71” is the API Gateway Stage endpoint URL.

We have a “Get” method defined at path “/order” in cdk_multienv_setup/

Testing the deployment


Succesful response would return :

Transaction: id-12314124124124

This sends the request to API Gateway Endpoint, which forwards it to our Lambda function