forked from mcnamarabrian/pycon2024
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.yaml
157 lines (144 loc) · 4.88 KB
/
template.yaml
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
Pycon US 2024 supporting code
Parameters:
AwsKmsArn:
Description: Enter the ARN of the key used to encrypt the Honeycomb API secret
Type: String
HoneycombSecretsArn:
Description: Enter the ARN where the Honeycomb secrets are stored
Type: String
AwsRegion:
Description: Enter the region to deploy the CloudFormation stack
Type: String
Default: us-east-1
AllowedValues:
- us-east-1
- us-east-2
- us-west-2
- eu-west-1
- eu-west-2
Mappings:
RegionMap:
us-east-1:
OtelLayerArn: arn:aws:lambda:us-east-1:901920570463:layer:aws-otel-python-amd64-ver-1-21-0:1
HoneycombEndpoint: api.honeycomb.io:443
us-east-2:
OtelLayerArn: arn:aws:lambda:us-east-2:901920570463:layer:aws-otel-python-amd64-ver-1-21-0:1
HoneycombEndpoint: api.honeycomb.io:443
us-west-2:
OtelLayerArn: arn:aws:lambda:us-west-2:901920570463:layer:aws-otel-python-amd64-ver-1-21-0:1
HoneycombEndpoint: api.honeycomb.io:443
eu-west-1:
OtelLayerArn: arn:aws:lambda:eu-west-1:901920570463:layer:aws-otel-python-amd64-ver-1-21-0:1
HoneycombEndpoint: api.eu1.honeycomb.io:443
eu-west-2:
OtelLayerArn: arn:aws:lambda:eu-west-2:901920570463:layer:aws-otel-python-amd64-ver-1-21-0:1
HoneycombEndpoint: api.eu1.honeycomb.io:443
Globals:
Function:
Runtime: python3.11
Timeout: 5
MemorySize: 256
Tracing: Active
Resources:
VanillaLogGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: !Sub "/aws/lambda/${VanillaFunction}"
RetentionInDays: 14
Tags:
- Key: function
Value: vanilla-log-group
VanillaFunction:
Type: AWS::Serverless::Function
Properties:
Description: Sample Lambda function without instrumentation - pycon us 2024
CodeUri: ./function/vanilla/
Handler: vanilla.handler
Policies:
- Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- xray:PutTraceSegments
- xray:PutTelemetryRecords
- xray:GetSamplingRules
- xray:GetSamplingTargets
- xray:GetSamplingStatisticsSummaries
Resource: '*'
InstrumentedLogGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: !Sub "/aws/lambda/${InstrumentedFunction}"
RetentionInDays: 14
Tags:
- Key: function
Value: instrumented-log-group
InstrumentedFunction:
Type: AWS::Serverless::Function
Properties:
Description: Sample Lambda function with instrumentation - pycon us 2024
CodeUri: ./function/instrumented/
Handler: instrumented.handler
Policies:
- Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- xray:PutTraceSegments
- xray:PutTelemetryRecords
- xray:GetSamplingRules
- xray:GetSamplingTargets
- xray:GetSamplingStatisticsSummaries
Resource: '*'
Environment:
Variables:
POWERTOOLS_SERVICE_NAME: instrumented-user-registration
POWERTOOLS_LOG_LEVEL: INFO
POWERTOOLS_METRICS_NAMESPACE: Pycon2024
OtelLogGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: !Sub "/aws/lambda/${OtelFunction}"
RetentionInDays: 14
Tags:
- Key: function
Value: otel-log-group
OtelFunction:
Type: AWS::Serverless::Function
Properties:
Description: Sample Lambda function with OTEL instrumentation - pycon us 2024
CodeUri: ./function/otel/
Handler: otel.handler
Tracing: PassThrough
MemorySize: 1024
Layers:
- !FindInMap [RegionMap, !Ref AwsRegion, OtelLayerArn]
Policies:
- KMSDecryptPolicy:
KeyId: !Ref AwsKmsArn
- AWSSecretsManagerGetSecretValuePolicy:
SecretArn: !Ref HoneycombSecretsArn
Environment:
Variables:
POWERTOOLS_SERVICE_NAME: otel-user-registration
POWERTOOLS_LOG_LEVEL: INFO
POWERTOOLS_METRICS_NAMESPACE: Pycon2024
AWS_LAMBDA_EXEC_WRAPPER: /opt/otel-instrument
OPENTELEMETRY_COLLECTOR_CONFIG_FILE: /var/task/otel-config.yaml
OTEL_PROPAGATORS: tracecontext
OTEL_SERVICE_NAME: otel-user-registration
HONEYCOMB_API_KEY: "{{resolve:secretsmanager:pycon2024/honeycomb:SecretString:api_key}}"
HONEYCOMB_ENDPOINT: !FindInMap [RegionMap, !Ref "AWS::Region", HoneycombEndpoint]
Outputs:
VanillaFunctionArn:
Description: ARN used for CLI testing
Value: !Ref VanillaFunction
InstrumentedFunction:
Description: ARN used for CLI testing
Value: !Ref InstrumentedFunction
OtelFunction:
Description: ARN used for CLI testing
Value: !Ref OtelFunction