|
| 1 | +AWSTemplateFormatVersion: '2010-09-09' |
| 2 | +Transform: AWS::Serverless-2016-10-31 |
| 3 | + |
| 4 | +Parameters: |
| 5 | + LambdaFunctionARN: |
| 6 | + Type: String |
| 7 | + Description: The ARN of the Lambda function to invoke |
| 8 | + |
| 9 | + WrapperHandler: |
| 10 | + Type: String |
| 11 | + Description: The path to the otel instrumentation executable |
| 12 | + Default: /opt/python/otel-instrument |
| 13 | + |
| 14 | + Runtime: |
| 15 | + Type: String |
| 16 | + Description: The language of the Lambda function |
| 17 | + Default: python |
| 18 | + AllowedValues: |
| 19 | + - python |
| 20 | + - nodejs |
| 21 | + - go |
| 22 | + |
| 23 | + Arch: |
| 24 | + Type: String |
| 25 | + Description: The architecture of the Lambda function |
| 26 | + Default: amd64 |
| 27 | + AllowedValues: |
| 28 | + - amd64 |
| 29 | + - arm64 |
| 30 | + |
| 31 | +Mappings: |
| 32 | + layers: |
| 33 | + python: |
| 34 | + amd64: arn:aws:lambda:eu-north-1:035955823196:layer:coralogix-aws-lambda-telemetry-exporter-python-x86_64:1 |
| 35 | + arm64: arn:aws:lambda:eu-north-1:035955823196:layer:coralogix-aws-lambda-telemetry-exporter-python-arm64:1 |
| 36 | + |
| 37 | + RegionMap: |
| 38 | + us-east-1: |
| 39 | + LambdaLayerARN: arn:aws:lambda:us-east-1:901920570463:layer:aws-otel-python38-ver-1-0-0:1 |
| 40 | + us-east-2: |
| 41 | + LambdaLayerARN: arn:aws:lambda:us-east-2:901920570463:layer:aws-otel-python38-ver-1-0-0:1 |
| 42 | + us-west-2: |
| 43 | + LambdaLayerARN: arn:aws:lambda:us-west-2:901920570463:layer:aws-otel-python38-ver-1-0-0:1 |
| 44 | + |
| 45 | +Resources: |
| 46 | + CustomResourceConfigureLambdaFunction: |
| 47 | + Type: 'AWS::CloudFormation::CustomResource' |
| 48 | + Properties: |
| 49 | + ServiceToken: !GetAtt AddConfigLambdaFunction.Arn |
| 50 | + LambdaArn: !Ref LambdaFunctionARN |
| 51 | + layers: |
| 52 | + - !FindInMap [layers, !Ref Runtime, !Ref Arch] |
| 53 | + env: |
| 54 | + AWS_LAMBDA_EXEC_WRAPPER: !Ref WrapperHandler |
| 55 | + |
| 56 | + |
| 57 | + AddConfigLambdaFunction: |
| 58 | + Type: AWS::Serverless::Function |
| 59 | + Properties: |
| 60 | + FunctionName: coralogix-otel-lambda-configure |
| 61 | + Handler: index.lambda_handler |
| 62 | + Runtime: python3.9 |
| 63 | + Policies: |
| 64 | + - Statement: |
| 65 | + - Sid: AllowLambdaConfigUpdatePolicy |
| 66 | + Effect: Allow |
| 67 | + Action: |
| 68 | + - lambda:UpdateFunctionConfiguration |
| 69 | + Resource: "*" |
| 70 | + |
| 71 | + InlineCode: | |
| 72 | + import boto3 |
| 73 | + import json |
| 74 | + import cfnresponse |
| 75 | +
|
| 76 | + def handler(event, context): |
| 77 | + print("Received event: " + json.dumps(event, indent=2)) |
| 78 | + lambda_client = boto3.client('lambda') |
| 79 | + lambda_client.update_function_configuration( |
| 80 | + FunctionName=event['ResourceProperties']['LambdaArn'], |
| 81 | + Layers=event['ResourceProperties']['layers'], |
| 82 | + Environment={ |
| 83 | + 'Variables': event['ResourceProperties']['env'] |
| 84 | + } |
| 85 | + ) |
| 86 | + return cfnresponse.SUCCESS |
| 87 | +
|
0 commit comments