Skip to content

Commit 6317a2a

Browse files
authored
feat(lambda): support observability for ESM ( DDB, Kinesis, SQS) (#32204)
### Reason for this change Lambda is introducing a new property in Event Sources named `MetricsConfig` to get enhanced metrics for user's event source that captures each stage of processing. Through this metrics customer can track flow of events through their EDA pipelines. This feature is currently supported for `DynamoDB`, `Kinesis` and `SQS` event sources only. ### Description of changes This new property can be opted in by setting the `MetricsConfig` field while creating event sources. The example of opting for `MetricsConfig` for dynamoDB event is shown below: ``` fn.addEventSource(new eventsources.DynamoEventSource(table, { startingPosition: lambda.StartingPosition.LATEST, metricsConfig: { metrics: [MetricType.EVENT_COUNT], } })) ``` Today there is only 1 metric type: EventCount. The `metrics` array can be either one element with `EventCount` or an empty array. More configuration support will be available in future ### Description of how you validated changes Have added unit test and integration test to validate the implementation ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent baa8561 commit 6317a2a

File tree

39 files changed

+3993
-1
lines changed

39 files changed

+3993
-1
lines changed

packages/@aws-cdk-testing/framework-integ/test/aws-lambda-event-sources/test/integ.dynamodb-with-metrics-config.js.snapshot/cdk.out

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-lambda-event-sources/test/integ.dynamodb-with-metrics-config.js.snapshot/integ.json

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-lambda-event-sources/test/integ.dynamodb-with-metrics-config.js.snapshot/lambda-event-source-metrics-config-dynamodb.assets.json

+19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,276 @@
1+
{
2+
"Resources": {
3+
"FServiceRole3AC82EE1": {
4+
"Type": "AWS::IAM::Role",
5+
"Properties": {
6+
"AssumeRolePolicyDocument": {
7+
"Statement": [
8+
{
9+
"Action": "sts:AssumeRole",
10+
"Effect": "Allow",
11+
"Principal": {
12+
"Service": "lambda.amazonaws.com"
13+
}
14+
}
15+
],
16+
"Version": "2012-10-17"
17+
},
18+
"ManagedPolicyArns": [
19+
{
20+
"Fn::Join": [
21+
"",
22+
[
23+
"arn:",
24+
{
25+
"Ref": "AWS::Partition"
26+
},
27+
":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
28+
]
29+
]
30+
}
31+
]
32+
}
33+
},
34+
"FServiceRoleDefaultPolicy17A19BFA": {
35+
"Type": "AWS::IAM::Policy",
36+
"Properties": {
37+
"PolicyDocument": {
38+
"Statement": [
39+
{
40+
"Action": "dynamodb:ListStreams",
41+
"Effect": "Allow",
42+
"Resource": "*"
43+
},
44+
{
45+
"Action": [
46+
"dynamodb:DescribeStream",
47+
"dynamodb:GetRecords",
48+
"dynamodb:GetShardIterator"
49+
],
50+
"Effect": "Allow",
51+
"Resource": {
52+
"Fn::GetAtt": [
53+
"TD925BC7E",
54+
"StreamArn"
55+
]
56+
}
57+
}
58+
],
59+
"Version": "2012-10-17"
60+
},
61+
"PolicyName": "FServiceRoleDefaultPolicy17A19BFA",
62+
"Roles": [
63+
{
64+
"Ref": "FServiceRole3AC82EE1"
65+
}
66+
]
67+
}
68+
},
69+
"FC4345940": {
70+
"Type": "AWS::Lambda::Function",
71+
"Properties": {
72+
"Code": {
73+
"ZipFile": "exports.handler = async function handler(event) {\n console.log('event:', JSON.stringify(event, undefined, 2));\n return { event };\n}"
74+
},
75+
"Handler": "index.handler",
76+
"Role": {
77+
"Fn::GetAtt": [
78+
"FServiceRole3AC82EE1",
79+
"Arn"
80+
]
81+
},
82+
"Runtime": "nodejs18.x"
83+
},
84+
"DependsOn": [
85+
"FServiceRoleDefaultPolicy17A19BFA",
86+
"FServiceRole3AC82EE1"
87+
]
88+
},
89+
"FDynamoDBEventSourcelambdaeventsourcemetricsconfigdynamodbT8ABCAB8CB3F48FC4": {
90+
"Type": "AWS::Lambda::EventSourceMapping",
91+
"Properties": {
92+
"BatchSize": 5,
93+
"EventSourceArn": {
94+
"Fn::GetAtt": [
95+
"TD925BC7E",
96+
"StreamArn"
97+
]
98+
},
99+
"FunctionName": {
100+
"Ref": "FC4345940"
101+
},
102+
"MetricsConfig": {
103+
"Metrics": []
104+
},
105+
"StartingPosition": "LATEST"
106+
}
107+
},
108+
"TD925BC7E": {
109+
"Type": "AWS::DynamoDB::Table",
110+
"Properties": {
111+
"AttributeDefinitions": [
112+
{
113+
"AttributeName": "id",
114+
"AttributeType": "S"
115+
}
116+
],
117+
"KeySchema": [
118+
{
119+
"AttributeName": "id",
120+
"KeyType": "HASH"
121+
}
122+
],
123+
"ProvisionedThroughput": {
124+
"ReadCapacityUnits": 5,
125+
"WriteCapacityUnits": 5
126+
},
127+
"StreamSpecification": {
128+
"StreamViewType": "NEW_IMAGE"
129+
}
130+
},
131+
"UpdateReplacePolicy": "Delete",
132+
"DeletionPolicy": "Delete"
133+
},
134+
"F5ServiceRole2E897519": {
135+
"Type": "AWS::IAM::Role",
136+
"Properties": {
137+
"AssumeRolePolicyDocument": {
138+
"Statement": [
139+
{
140+
"Action": "sts:AssumeRole",
141+
"Effect": "Allow",
142+
"Principal": {
143+
"Service": "lambda.amazonaws.com"
144+
}
145+
}
146+
],
147+
"Version": "2012-10-17"
148+
},
149+
"ManagedPolicyArns": [
150+
{
151+
"Fn::Join": [
152+
"",
153+
[
154+
"arn:",
155+
{
156+
"Ref": "AWS::Partition"
157+
},
158+
":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
159+
]
160+
]
161+
}
162+
]
163+
}
164+
},
165+
"F5ServiceRoleDefaultPolicyF3745DE6": {
166+
"Type": "AWS::IAM::Policy",
167+
"Properties": {
168+
"PolicyDocument": {
169+
"Statement": [
170+
{
171+
"Action": "dynamodb:ListStreams",
172+
"Effect": "Allow",
173+
"Resource": "*"
174+
},
175+
{
176+
"Action": [
177+
"dynamodb:DescribeStream",
178+
"dynamodb:GetRecords",
179+
"dynamodb:GetShardIterator"
180+
],
181+
"Effect": "Allow",
182+
"Resource": {
183+
"Fn::GetAtt": [
184+
"TD925BC7E",
185+
"StreamArn"
186+
]
187+
}
188+
}
189+
],
190+
"Version": "2012-10-17"
191+
},
192+
"PolicyName": "F5ServiceRoleDefaultPolicyF3745DE6",
193+
"Roles": [
194+
{
195+
"Ref": "F5ServiceRole2E897519"
196+
}
197+
]
198+
}
199+
},
200+
"F5B560B5F9": {
201+
"Type": "AWS::Lambda::Function",
202+
"Properties": {
203+
"Code": {
204+
"ZipFile": "exports.handler = async function handler(event) {\n console.log('event:', JSON.stringify(event, undefined, 2));\n return { event };\n}"
205+
},
206+
"Handler": "index.handler",
207+
"Role": {
208+
"Fn::GetAtt": [
209+
"F5ServiceRole2E897519",
210+
"Arn"
211+
]
212+
},
213+
"Runtime": "nodejs18.x"
214+
},
215+
"DependsOn": [
216+
"F5ServiceRoleDefaultPolicyF3745DE6",
217+
"F5ServiceRole2E897519"
218+
]
219+
},
220+
"F5DynamoDBEventSourcelambdaeventsourcemetricsconfigdynamodbT8ABCAB8CD0816D3E": {
221+
"Type": "AWS::Lambda::EventSourceMapping",
222+
"Properties": {
223+
"BatchSize": 5,
224+
"EventSourceArn": {
225+
"Fn::GetAtt": [
226+
"TD925BC7E",
227+
"StreamArn"
228+
]
229+
},
230+
"FunctionName": {
231+
"Ref": "F5B560B5F9"
232+
},
233+
"MetricsConfig": {
234+
"Metrics": [
235+
"EventCount"
236+
]
237+
},
238+
"StartingPosition": "LATEST"
239+
}
240+
}
241+
},
242+
"Parameters": {
243+
"BootstrapVersion": {
244+
"Type": "AWS::SSM::Parameter::Value<String>",
245+
"Default": "/cdk-bootstrap/hnb659fds/version",
246+
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]"
247+
}
248+
},
249+
"Rules": {
250+
"CheckBootstrapVersion": {
251+
"Assertions": [
252+
{
253+
"Assert": {
254+
"Fn::Not": [
255+
{
256+
"Fn::Contains": [
257+
[
258+
"1",
259+
"2",
260+
"3",
261+
"4",
262+
"5"
263+
],
264+
{
265+
"Ref": "BootstrapVersion"
266+
}
267+
]
268+
}
269+
]
270+
},
271+
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI."
272+
}
273+
]
274+
}
275+
}
276+
}

packages/@aws-cdk-testing/framework-integ/test/aws-lambda-event-sources/test/integ.dynamodb-with-metrics-config.js.snapshot/lambdaeventsourcedynamodbwithmetricsDefaultTestDeployAssertC1C197C4.assets.json

+19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-lambda-event-sources/test/integ.dynamodb-with-metrics-config.js.snapshot/lambdaeventsourcedynamodbwithmetricsDefaultTestDeployAssertC1C197C4.template.json

+36
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)