Skip to content

Commit 9032e95

Browse files
committed
remove typo
1 parent 71154fc commit 9032e95

File tree

3 files changed

+134
-2
lines changed

3 files changed

+134
-2
lines changed

opentelemetry/ecs-ec2/template.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ Mappings:
124124
id: docker_log_json_parser
125125
routes:
126126
- output: json_parser
127-
expr: 'body matches "^\\{\"log\".*\\}xxx"'
127+
expr: 'body matches "^\\{\"log\".*\\}"'
128128
default: move_log_file_path
129129
130130
- type: json_parser
@@ -276,7 +276,7 @@ Mappings:
276276
id: docker_log_json_parser
277277
routes:
278278
- output: json_parser
279-
expr: 'body matches "^\\{\"log\".*\\}xxx"'
279+
expr: 'body matches "^\\{\"log\".*\\}"'
280280
default: move_log_file_path
281281
282282
- type: json_parser

opentelemetry/lambda/script.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import boto3
2+
import cfnresponse
3+
import json
4+
5+
def handler(event, context):
6+
print("received event: " + json.dumps(event, indent=2))
7+
8+
try:
9+
status = cfnresponse.SUCCESS
10+
11+
if event['RequestType'] in ['Create', 'Update']:
12+
lambda_arn = event['ResourceProperties']['LambdaArn']
13+
lambda_client = boto3.client('lambda')
14+
15+
# Get the current environment variables of the Lambda function
16+
function_configuration = lambda_client.get_function_configuration(FunctionName=lambda_arn)
17+
current_env = function_configuration['Environment']['Variables']
18+
19+
# Merge the current environment variables with any new ones specified in the CloudFormation event
20+
# new_environment = current_environment.copy()
21+
current_env.update(event['ResourceProperties']['env'])
22+
23+
# Get the list of layers to add to the Lambda function
24+
layers = event['ResourceProperties'].get('LayerArns', [])
25+
26+
# Add the specified layers and environment variables to the Lambda function
27+
lambda_client.update_function_configuration(
28+
FunctionName=lambda_arn,
29+
Environment={'Variables': current_env},
30+
Layers=layers)
31+
32+
if event['RequestType'] == 'Delete':
33+
# TODO: implement delete logic
34+
pass
35+
36+
37+
except Exception as e:
38+
print(f"custom resource failed to update layers and env vars: {e}")
39+
status = cfnresponse.FAILED
40+
41+
finally:
42+
# Send a status response to CloudFormation
43+
response_data = {}
44+
cfnresponse.send(event, context, status, response_data)
45+
return

opentelemetry/lambda/template.yaml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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

Comments
 (0)