|
1 | 1 | import * as cdk from 'aws-cdk-lib/core'; |
2 | 2 | import { Construct } from 'constructs'; |
3 | | -// import * as sqs from 'aws-cdk-lib/aws-sqs'; |
| 3 | +import * as lambda from 'aws-cdk-lib/aws-lambda'; |
| 4 | +import * as apigwv2 from 'aws-cdk-lib/aws-apigatewayv2'; |
| 5 | +import * as integrations from 'aws-cdk-lib/aws-apigatewayv2-integrations'; |
| 6 | +import * as path from 'path'; |
4 | 7 |
|
5 | 8 | export class InfraStack extends cdk.Stack { |
6 | 9 | constructor(scope: Construct, id: string, props?: cdk.StackProps) { |
7 | 10 | super(scope, id, props); |
8 | 11 |
|
9 | | - // The code that defines your stack goes here |
| 12 | + const nodeModulesLayer = new lambda.LayerVersion(this, 'NodeModulesLayer', { |
| 13 | + code: lambda.Code.fromAsset(path.join(__dirname, '../../layer')), |
| 14 | + compatibleRuntimes: [lambda.Runtime.NODEJS_20_X], |
| 15 | + description: 'Production node_modules for NestJS Lambda', |
| 16 | + }); |
10 | 17 |
|
11 | | - // example resource |
12 | | - // const queue = new sqs.Queue(this, 'InfraQueue', { |
13 | | - // visibilityTimeout: cdk.Duration.seconds(300) |
14 | | - // }); |
| 18 | + const nestApiLambda = new lambda.Function(this, 'NestApiLambdaFunction', { |
| 19 | + runtime: lambda.Runtime.NODEJS_20_X, |
| 20 | + handler: 'src/lambda.handler', |
| 21 | + code: lambda.Code.fromAsset(path.join(__dirname, '../../dist'), { |
| 22 | + exclude: ['infra', 'tsconfig*'], |
| 23 | + }), |
| 24 | + memorySize: 512, |
| 25 | + layers: [nodeModulesLayer], |
| 26 | + }); |
| 27 | + |
| 28 | + const httpApi = new apigwv2.HttpApi(this, 'HttpApi', { |
| 29 | + defaultIntegration: new integrations.HttpLambdaIntegration( |
| 30 | + 'LambdaIntegration', |
| 31 | + nestApiLambda, |
| 32 | + ), |
| 33 | + }); |
| 34 | + |
| 35 | + new cdk.CfnOutput(this, 'HttpApiUrl', { |
| 36 | + value: httpApi.url!, |
| 37 | + }); |
15 | 38 | } |
16 | 39 | } |
0 commit comments