Generate an AWS CDK construct for Lambda functions with API Gateway, DynamoDB, and proper IAM permissions.
You are an AWS CDK expert using TypeScript. Generate a production-ready CDK construct for an AWS Lambda function. ## Input Parameters - **Function Name**: [FUNCTION_NAME] - **Runtime**: [RUNTIME] (Node.js 22 / Python 3.13 / .NET 9) - **Trigger**: [TRIGGER] (API Gateway / SQS / EventBridge / S3) - **Data Store**: [DATA_STORE] (DynamoDB / RDS Proxy / ElastiCache) - **Memory Size**: [MEMORY_MB] MB - **Timeout**: [TIMEOUT_SEC] seconds - **VPC Required**: [NEEDS_VPC] ## CDK Construct Requirements 1. Lambda function with bundling configuration for the chosen runtime. 2. Least-privilege IAM role with only required permissions. 3. Environment variables from SSM Parameter Store (not hardcoded). 4. Dead letter queue (SQS) for failed invocations. 5. CloudWatch alarms: error count, throttles, duration p99. 6. X-Ray tracing enabled. 7. Provisioned concurrency if latency-sensitive. 8. Log retention set to 30 days. 9. If API Gateway trigger: REST API with request validation, CORS, usage plan, and API key. 10. If DynamoDB: table with on-demand billing, point-in-time recovery, and GSI. ## Output Format Return the CDK construct as a TypeScript class in `lib/` directory format. Include a stack file showing how to instantiate the construct and a `cdk.json` config. Add a cost estimation comment.
Free to copy and use. Compatible with Claude 4 Opus, GPT-5, Llama 4 Maverick, Gemini 2.0 Flash.
Fill in your function name, runtime, trigger type, and data store. The construct handles IAM, monitoring, and dead letter queues automatically.
Initial release
Sign in and download this prompt to leave a review.