|
| 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 { createLogGroup, defaultDatadogEnvVariables, defaultDatadogSecretPolicy, getExtensionLayer, getPython313Layer } from '../util'; |
| 5 | + |
| 6 | +export class BasePythonStack extends cdk.Stack { |
| 7 | + constructor(scope: Construct, id: string, props: cdk.StackProps) { |
| 8 | + super(scope, id, props); |
| 9 | + |
| 10 | + const pythonFunctionName = `${id}-lambda` |
| 11 | + const pythonFunction = new lambda.Function(this, pythonFunctionName, { |
| 12 | + runtime: lambda.Runtime.PYTHON_3_13, |
| 13 | + architecture: lambda.Architecture.ARM_64, |
| 14 | + handler: 'datadog_lambda.handler.handler', |
| 15 | + code: lambda.Code.fromAsset('./lambda/base-python'), |
| 16 | + functionName: pythonFunctionName, |
| 17 | + timeout: cdk.Duration.seconds(30), |
| 18 | + memorySize: 256, |
| 19 | + environment: { |
| 20 | + ...defaultDatadogEnvVariables, |
| 21 | + DD_SERVICE: pythonFunctionName, |
| 22 | + DD_TRACE_ENABLED: 'true', |
| 23 | + DD_LAMBDA_HANDLER: 'lambda_function.handler', |
| 24 | + DD_LOG_LEVEL: 'debug', |
| 25 | + DD_TRACE_AGENT_URL: 'http://127.0.0.1:8126', |
| 26 | + DD_COLD_START_TRACING: 'true', |
| 27 | + DD_MIN_COLD_START_DURATION: '0', |
| 28 | + }, |
| 29 | + logGroup: createLogGroup(this, pythonFunctionName) |
| 30 | + }); |
| 31 | + pythonFunction.addToRolePolicy(defaultDatadogSecretPolicy) |
| 32 | + pythonFunction.addLayers(getExtensionLayer(this)); |
| 33 | + pythonFunction.addLayers(getPython313Layer(this)); |
| 34 | + } |
| 35 | +} |
0 commit comments