mirror of
https://github.com/swift-server/swift-aws-lambda-runtime.git
synced 2026-06-02 07:27:33 +00:00
18660fcdd1
added an example showing how to deploy with the CDK This code is the basis for the upcoming CDK section in the deployment guide
55 lines
1.8 KiB
TypeScript
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',
|
|
});
|
|
}
|
|
}
|
|
|