Skip to content

Commit 6a161b9

Browse files
committed
🎉 import from existing project
0 parents  commit 6a161b9

16 files changed

+3236
-0
lines changed

.gitignore

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
*.js
2+
!jest.config.js
3+
*.d.ts
4+
node_modules
5+
6+
# CDK asset staging directory
7+
.cdk.staging
8+
cdk.out
9+
10+
# integration test env vars cache
11+
testConfigCache.json
12+
testEnvVarsCache.json

.nvmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v18.16.0

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Lambda internal extension example
2+
3+
This example shows how to create a simple Lambda internal extension
4+
5+

bin/app.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env node
2+
import "source-map-support/register";
3+
import * as cdk from "aws-cdk-lib";
4+
import { AppStack } from "../lib/app-stack";
5+
6+
const app = new cdk.App();
7+
new AppStack(app, "LambdaInternalExtensionExample");

cdk.json

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"app": "pnpm ts-node --prefer-ts-exts bin/app.ts",
3+
"watch": {
4+
"include": ["**"],
5+
"exclude": [
6+
"README.md",
7+
"cdk*.json",
8+
"**/*.d.ts",
9+
"tsconfig.json",
10+
"package*.json",
11+
"yarn.lock",
12+
"node_modules",
13+
"test"
14+
]
15+
},
16+
"context": {
17+
"@aws-cdk/aws-lambda:recognizeLayerVersion": true,
18+
"@aws-cdk/core:checkSecretUsage": true,
19+
"@aws-cdk/core:target-partitions": ["aws", "aws-cn"],
20+
"@aws-cdk-containers/ecs-service-extensions:enableDefaultLogDriver": true,
21+
"@aws-cdk/aws-ec2:uniqueImdsv2TemplateName": true,
22+
"@aws-cdk/aws-ecs:arnFormatIncludesClusterName": true,
23+
"@aws-cdk/aws-iam:minimizePolicies": true,
24+
"@aws-cdk/core:validateSnapshotRemovalPolicy": true,
25+
"@aws-cdk/aws-codepipeline:crossAccountKeyAliasStackSafeResourceName": true,
26+
"@aws-cdk/aws-s3:createDefaultLoggingPolicy": true,
27+
"@aws-cdk/aws-sns-subscriptions:restrictSqsDescryption": true,
28+
"@aws-cdk/aws-apigateway:disableCloudWatchRole": true,
29+
"@aws-cdk/core:enablePartitionLiterals": true,
30+
"@aws-cdk/aws-events:eventsTargetQueueSameAccount": true,
31+
"@aws-cdk/aws-iam:standardizedServicePrincipals": true,
32+
"@aws-cdk/aws-ecs:disableExplicitDeploymentControllerForCircuitBreaker": true,
33+
"testEnvVarTypePath": "./testEnvVars.ts"
34+
}
35+
}

lib/app-stack.ts

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import * as cdk from "aws-cdk-lib";
2+
import { Construct } from "constructs";
3+
import {
4+
Architecture,
5+
Code,
6+
LayerVersion,
7+
Runtime,
8+
} from "aws-cdk-lib/aws-lambda";
9+
import * as path from "path";
10+
import { HttpApi, HttpMethod } from "@aws-cdk/aws-apigatewayv2-alpha";
11+
import { TestEnvVar } from "@swarmion/integration-tests";
12+
import { NodejsFunction } from "aws-cdk-lib/aws-lambda-nodejs";
13+
import { HttpLambdaIntegration } from "@aws-cdk/aws-apigatewayv2-integrations-alpha";
14+
15+
export class AppStack extends cdk.Stack {
16+
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
17+
super(scope, id, props);
18+
19+
const httpApi = new HttpApi(this, "HttpApi");
20+
21+
new TestEnvVar(this, "API_URL", {
22+
value: httpApi.url as string,
23+
});
24+
25+
const interceptorLayer = new LayerVersion(this, "Interceptor", {
26+
compatibleRuntimes: [Runtime.NODEJS_18_X],
27+
compatibleArchitectures: [Architecture.ARM_64],
28+
code: Code.fromAsset("src/layers/interceptorExtension"),
29+
});
30+
31+
const helloFunction = new NodejsFunction(this, "Hello", {
32+
architecture: Architecture.ARM_64,
33+
memorySize: 256,
34+
timeout: cdk.Duration.seconds(5),
35+
runtime: Runtime.NODEJS_18_X,
36+
handler: "handler",
37+
entry: path.join(__dirname, `/../src/functions/hello/handler.ts`),
38+
environment: {
39+
NODE_OPTIONS: "--enable-source-maps --require /opt/interceptor.js",
40+
},
41+
layers: [interceptorLayer],
42+
});
43+
44+
const syncNftIntegration = new HttpLambdaIntegration(
45+
"Hello",
46+
helloFunction
47+
);
48+
49+
httpApi.addRoutes({
50+
path: "/hello",
51+
methods: [HttpMethod.POST],
52+
integration: syncNftIntegration,
53+
});
54+
}
55+
}

package.json

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"name": "lambda-internal-extension-example",
3+
"version": "0.0.1",
4+
"bin": {
5+
"app": "bin/app.js"
6+
},
7+
"scripts": {
8+
"preinstall": "npx only-allow pnpm",
9+
"build": "tsc",
10+
"test:type": "tsc --noEmit",
11+
"test:unit": "vitest",
12+
"test:integration": "vitest run --config vitest.integration.config.ts --passWithNoTests",
13+
"cdk": "cdk",
14+
"deploy": "pnpm build:layer && cdk deploy",
15+
"start": "cdk watch",
16+
"build:layer": "./node_modules/.bin/esbuild ./src/layers/interceptorExtension/interceptor.ts --bundle --outfile='./src/layers/interceptorExtension/interceptor.js' --platform=node"
17+
},
18+
"devDependencies": {
19+
"@swarmion/integration-tests": "^0.27.0",
20+
"@types/node": "^18.16.2",
21+
"aws-cdk": "^2.77.0",
22+
"esbuild": "^0.16.17",
23+
"ts-node": "^10.9.1",
24+
"typescript": "4.9.4",
25+
"vite-tsconfig-paths": "^4.2.0",
26+
"vitest": "^0.26.3"
27+
},
28+
"dependencies": {
29+
"@aws-cdk/aws-apigatewayv2-alpha": "^2.77.0-alpha.0",
30+
"@aws-cdk/aws-apigatewayv2-integrations-alpha": "^2.77.0-alpha.0",
31+
"aws-cdk-lib": "^2.77.0",
32+
"constructs": "^10.2.9",
33+
"msw": "^1.2.1",
34+
"node-fetch": "^3.3.1",
35+
"prettier": "^2.8.8",
36+
"source-map-support": "^0.5.21"
37+
}
38+
}

0 commit comments

Comments
 (0)