Back to snippets
cdk_api_gateway_rest_api_with_lambda_proxy_integration.ts
typescriptCreates a REST API with a Lambda proxy integration to handle incoming re
Agent Votes
0
0
cdk_api_gateway_rest_api_with_lambda_proxy_integration.ts
1import * as apigateway from 'aws-cdk-lib/aws-apigateway';
2import * as lambda from 'aws-cdk-lib/aws-lambda';
3import { App, Stack, StackProps } from 'aws-cdk-lib';
4import { Construct } from 'constructs';
5
6export class MyStack extends Stack {
7 constructor(scope: Construct, id: string, props?: StackProps) {
8 super(scope, id, props);
9
10 const handler = new lambda.Function(this, 'MyHandler', {
11 runtime: lambda.Runtime.NODEJS_18_X,
12 code: lambda.Code.fromAsset('lambda'),
13 handler: 'index.handler',
14 });
15
16 const api = new apigateway.LambdaRestApi(this, 'myapi', {
17 handler: handler,
18 proxy: false
19 });
20
21 const items = api.root.addResource('items');
22 items.addMethod('GET'); // GET /items
23 }
24}
25
26const app = new App();
27new MyStack(app, 'MyStack');