-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathsnapstart.ts
More file actions
106 lines (101 loc) · 4.08 KB
/
snapstart.ts
File metadata and controls
106 lines (101 loc) · 4.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import * as cdk from 'aws-cdk-lib';
import * as lambda from 'aws-cdk-lib/aws-lambda';
import { Construct } from 'constructs';
import {
createLogGroup,
defaultDatadogEnvVariables,
defaultDatadogSecretPolicy,
getExtensionLayer,
getPython313Layer,
getJava21Layer,
getDotnet8Layer
} from '../util';
export class Snapstart extends cdk.Stack {
constructor(scope: Construct, id: string, props: cdk.StackProps) {
super(scope, id, props);
const extensionLayer = getExtensionLayer(this);
const python313Layer = getPython313Layer(this);
const java21Layer = getJava21Layer(this);
const dotnet8Layer = getDotnet8Layer(this);
const javaFunctionName = `${id}-java-lambda`;
const javaFunction = new lambda.Function(this, javaFunctionName, {
runtime: lambda.Runtime.JAVA_21,
architecture: lambda.Architecture.ARM_64,
handler: 'example.SnapstartHandler::handleRequest',
code: lambda.Code.fromAsset('./lambda/snapstart-java/target/function.jar'),
functionName: javaFunctionName,
timeout: cdk.Duration.seconds(30),
memorySize: 512,
snapStart: lambda.SnapStartConf.ON_PUBLISHED_VERSIONS,
environment: {
...defaultDatadogEnvVariables,
DD_SERVICE: javaFunctionName,
AWS_LAMBDA_EXEC_WRAPPER: '/opt/datadog_wrapper',
DD_TRACE_ENABLED: 'true',
},
logGroup: createLogGroup(this, javaFunctionName)
});
javaFunction.addToRolePolicy(defaultDatadogSecretPolicy);
javaFunction.addLayers(extensionLayer);
javaFunction.addLayers(java21Layer);
const javaVersion = javaFunction.currentVersion;
const javaAlias = new lambda.Alias(this, `${javaFunctionName}-snapstart-alias`, {
aliasName: 'snapstart',
version: javaVersion,
});
const pythonFunctionName = `${id}-python-lambda`;
const pythonFunction = new lambda.Function(this, pythonFunctionName, {
runtime: lambda.Runtime.PYTHON_3_13,
architecture: lambda.Architecture.ARM_64,
handler: 'datadog_lambda.handler.handler',
code: lambda.Code.fromAsset('./lambda/snapstart-python'),
functionName: pythonFunctionName,
timeout: cdk.Duration.seconds(30),
memorySize: 512,
snapStart: lambda.SnapStartConf.ON_PUBLISHED_VERSIONS,
environment: {
...defaultDatadogEnvVariables,
DD_SERVICE: pythonFunctionName,
DD_TRACE_ENABLED: 'true',
DD_LAMBDA_HANDLER: 'lambda_function.handler',
DD_TRACE_AGENT_URL: 'http://127.0.0.1:8126',
DD_COLD_START_TRACING: 'true',
DD_MIN_COLD_START_DURATION: '0',
},
logGroup: createLogGroup(this, pythonFunctionName)
});
pythonFunction.addToRolePolicy(defaultDatadogSecretPolicy);
pythonFunction.addLayers(extensionLayer);
pythonFunction.addLayers(python313Layer);
const pythonVersion = pythonFunction.currentVersion;
const pythonAlias = new lambda.Alias(this, `${pythonFunctionName}-snapstart-alias`, {
aliasName: 'snapstart',
version: pythonVersion,
});
const dotnetFunctionName = `${id}-dotnet-lambda`;
const dotnetFunction = new lambda.Function(this, dotnetFunctionName, {
runtime: lambda.Runtime.DOTNET_8,
architecture: lambda.Architecture.ARM_64,
handler: 'Function::Function.SnapstartHandler::FunctionHandler',
code: lambda.Code.fromAsset('./lambda/snapstart-dotnet/bin/function.zip'),
functionName: dotnetFunctionName,
timeout: cdk.Duration.seconds(30),
memorySize: 512,
snapStart: lambda.SnapStartConf.ON_PUBLISHED_VERSIONS,
environment: {
...defaultDatadogEnvVariables,
DD_SERVICE: dotnetFunctionName,
AWS_LAMBDA_EXEC_WRAPPER: '/opt/datadog_wrapper',
},
logGroup: createLogGroup(this, dotnetFunctionName)
});
dotnetFunction.addToRolePolicy(defaultDatadogSecretPolicy);
dotnetFunction.addLayers(extensionLayer);
dotnetFunction.addLayers(dotnet8Layer);
const dotnetVersion = dotnetFunction.currentVersion;
const dotnetAlias = new lambda.Alias(this, `${dotnetFunctionName}-snapstart-alias`, {
aliasName: 'snapstart',
version: dotnetVersion,
});
}
}