|
| 1 | +import * as cdk from 'aws-cdk-lib'; |
| 2 | +import * as lambda from 'aws-cdk-lib/aws-lambda'; |
| 3 | +import { Construct } from 'constructs'; |
| 4 | +import { |
| 5 | + createLogGroup, |
| 6 | + defaultDatadogEnvVariables, |
| 7 | + defaultDatadogSecretPolicy, |
| 8 | + getExtensionLayer, |
| 9 | + getDefaultNodeLayer, |
| 10 | + defaultNodeRuntime, |
| 11 | +} from '../util'; |
| 12 | + |
| 13 | +// Durable-function cold-start metric tag test. |
| 14 | +// The Lambda Telemetry API only reports a `platform.initStart` runtimeVersion |
| 15 | +// containing "DurableFunction" for functions actually configured with |
| 16 | +// `durableConfig`, so this stack deploys one durable and one non-durable |
| 17 | +// function to exercise bottlecap's `durable_function:true` tagging on the |
| 18 | +// cold-start `aws.lambda.enhanced.invocations` metric end-to-end. |
| 19 | +export class DurableColdStart extends cdk.Stack { |
| 20 | + constructor(scope: Construct, id: string, props: cdk.StackProps) { |
| 21 | + super(scope, id, props); |
| 22 | + |
| 23 | + const extensionLayer = getExtensionLayer(this); |
| 24 | + const nodeLayer = getDefaultNodeLayer(this); |
| 25 | + |
| 26 | + const durableFunctionName = `${id}-durable-lambda`; |
| 27 | + const durableFunction = new lambda.Function(this, durableFunctionName, { |
| 28 | + runtime: defaultNodeRuntime, |
| 29 | + architecture: lambda.Architecture.ARM_64, |
| 30 | + handler: '/opt/nodejs/node_modules/datadog-lambda-js/handler.handler', |
| 31 | + code: lambda.Code.fromAsset('./lambda/default-node'), |
| 32 | + functionName: durableFunctionName, |
| 33 | + timeout: cdk.Duration.seconds(30), |
| 34 | + memorySize: 256, |
| 35 | + durableConfig: { |
| 36 | + executionTimeout: cdk.Duration.minutes(5), |
| 37 | + }, |
| 38 | + environment: { |
| 39 | + ...defaultDatadogEnvVariables, |
| 40 | + DD_SERVICE: durableFunctionName, |
| 41 | + DD_TRACE_ENABLED: 'true', |
| 42 | + DD_LAMBDA_HANDLER: 'index.handler', |
| 43 | + }, |
| 44 | + logGroup: createLogGroup(this, durableFunctionName), |
| 45 | + }); |
| 46 | + durableFunction.addToRolePolicy(defaultDatadogSecretPolicy); |
| 47 | + durableFunction.addLayers(extensionLayer); |
| 48 | + durableFunction.addLayers(nodeLayer); |
| 49 | + |
| 50 | + const nonDurableFunctionName = `${id}-non-durable-lambda`; |
| 51 | + const nonDurableFunction = new lambda.Function(this, nonDurableFunctionName, { |
| 52 | + runtime: defaultNodeRuntime, |
| 53 | + architecture: lambda.Architecture.ARM_64, |
| 54 | + handler: '/opt/nodejs/node_modules/datadog-lambda-js/handler.handler', |
| 55 | + code: lambda.Code.fromAsset('./lambda/default-node'), |
| 56 | + functionName: nonDurableFunctionName, |
| 57 | + timeout: cdk.Duration.seconds(30), |
| 58 | + memorySize: 256, |
| 59 | + environment: { |
| 60 | + ...defaultDatadogEnvVariables, |
| 61 | + DD_SERVICE: nonDurableFunctionName, |
| 62 | + DD_TRACE_ENABLED: 'true', |
| 63 | + DD_LAMBDA_HANDLER: 'index.handler', |
| 64 | + }, |
| 65 | + logGroup: createLogGroup(this, nonDurableFunctionName), |
| 66 | + }); |
| 67 | + nonDurableFunction.addToRolePolicy(defaultDatadogSecretPolicy); |
| 68 | + nonDurableFunction.addLayers(extensionLayer); |
| 69 | + nonDurableFunction.addLayers(nodeLayer); |
| 70 | + } |
| 71 | +} |
0 commit comments