Files
swift-aws-lambda-runtime/Examples/CDK/infra/lib/lambda-api-project-stack.ts
T
Sébastien Stormacq 18660fcdd1 [examples] Add CDK deployment example (#431)
added an example showing how to deploy with the CDK
This code is the basis for the upcoming CDK section in the deployment
guide
2024-12-21 10:39:13 +01:00

55 lines
1.8 KiB
TypeScript

//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftAWSLambdaRuntime open source project
//
// Copyright (c) 2024 Apple Inc. and the SwiftAWSLambdaRuntime project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of SwiftAWSLambdaRuntime project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//
import * as cdk from 'aws-cdk-lib';
import * as lambda from 'aws-cdk-lib/aws-lambda';
import * as apigateway from 'aws-cdk-lib/aws-apigatewayv2';
import { HttpLambdaIntegration } from 'aws-cdk-lib/aws-apigatewayv2-integrations';
export class LambdaApiStack extends cdk.Stack {
constructor(scope: cdk.App, id: string, props?: cdk.StackProps) {
super(scope, id, props);
// Create the Lambda function
const lambdaFunction = new lambda.Function(this, 'SwiftLambdaFunction', {
runtime: lambda.Runtime.PROVIDED_AL2,
architecture: lambda.Architecture.ARM_64,
handler: 'bootstrap',
code: lambda.Code.fromAsset('../.build/plugins/AWSLambdaPackager/outputs/AWSLambdaPackager/APIGatewayLambda/APIGatewayLambda.zip'),
memorySize: 512,
timeout: cdk.Duration.seconds(30),
environment: {
LOG_LEVEL: 'debug',
},
});
// Create the integration
const integration = new HttpLambdaIntegration(
'LambdaIntegration',
lambdaFunction
);
// Create HTTP API with the integration
const httpApi = new apigateway.HttpApi(this, 'HttpApi', {
defaultIntegration: integration,
});
// Output the API URL
new cdk.CfnOutput(this, 'ApiUrl', {
value: httpApi.url ?? 'Something went wrong',
});
}
}