This repository contains code for provisioning an AWS Lambda function within a VPC and enabling it to access the internet using AWS Cloud Development Kit (CDK).
- VPC Creation: A VPC with both public and private subnets is created.
- NAT Gateway: A NAT Gateway is provisioned in the public subnet to allow internet access from the private subnet.
- Lambda Function: The Lambda function is launched in the private subnet with necessary permissions and configurations to manage network interfaces and access the internet via the NAT Gateway.
- Node.js (v12.x or later)
- AWS CDK (v2.x or later)
- AWS CLI configured with appropriate permissions
-
Clone the repository:
git clone https://github.com/mikaeelkhalid/lambda-function-vpc-aws-cdk.git cd lambda-function-vpc-aws-cdk
-
Install dependencies:
npm install
To deploy the stack, run:
cdk deploy
This command will provision the VPC, NAT Gateway, and the Lambda function with the required configurations.
To delete the resources and avoid ongoing costs from the NAT Gateway, run:
cdk destroy
For detailed explanation and code snippets, refer to the following blog post.
❗ Remember to destroy the stack to avoid unnecessary costs.