-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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*
- Loading branch information
1 parent
baa8561
commit 6317a2a
Showing
39 changed files
with
3,993 additions
and
1 deletion.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
...test/aws-lambda-event-sources/test/integ.dynamodb-with-metrics-config.js.snapshot/cdk.out
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
12 changes: 12 additions & 0 deletions
12
...t/aws-lambda-event-sources/test/integ.dynamodb-with-metrics-config.js.snapshot/integ.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
19 changes: 19 additions & 0 deletions
19
...b-with-metrics-config.js.snapshot/lambda-event-source-metrics-config-dynamodb.assets.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
276 changes: 276 additions & 0 deletions
276
...with-metrics-config.js.snapshot/lambda-event-source-metrics-config-dynamodb.template.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,276 @@ | ||
{ | ||
"Resources": { | ||
"FServiceRole3AC82EE1": { | ||
"Type": "AWS::IAM::Role", | ||
"Properties": { | ||
"AssumeRolePolicyDocument": { | ||
"Statement": [ | ||
{ | ||
"Action": "sts:AssumeRole", | ||
"Effect": "Allow", | ||
"Principal": { | ||
"Service": "lambda.amazonaws.com" | ||
} | ||
} | ||
], | ||
"Version": "2012-10-17" | ||
}, | ||
"ManagedPolicyArns": [ | ||
{ | ||
"Fn::Join": [ | ||
"", | ||
[ | ||
"arn:", | ||
{ | ||
"Ref": "AWS::Partition" | ||
}, | ||
":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" | ||
] | ||
] | ||
} | ||
] | ||
} | ||
}, | ||
"FServiceRoleDefaultPolicy17A19BFA": { | ||
"Type": "AWS::IAM::Policy", | ||
"Properties": { | ||
"PolicyDocument": { | ||
"Statement": [ | ||
{ | ||
"Action": "dynamodb:ListStreams", | ||
"Effect": "Allow", | ||
"Resource": "*" | ||
}, | ||
{ | ||
"Action": [ | ||
"dynamodb:DescribeStream", | ||
"dynamodb:GetRecords", | ||
"dynamodb:GetShardIterator" | ||
], | ||
"Effect": "Allow", | ||
"Resource": { | ||
"Fn::GetAtt": [ | ||
"TD925BC7E", | ||
"StreamArn" | ||
] | ||
} | ||
} | ||
], | ||
"Version": "2012-10-17" | ||
}, | ||
"PolicyName": "FServiceRoleDefaultPolicy17A19BFA", | ||
"Roles": [ | ||
{ | ||
"Ref": "FServiceRole3AC82EE1" | ||
} | ||
] | ||
} | ||
}, | ||
"FC4345940": { | ||
"Type": "AWS::Lambda::Function", | ||
"Properties": { | ||
"Code": { | ||
"ZipFile": "exports.handler = async function handler(event) {\n console.log('event:', JSON.stringify(event, undefined, 2));\n return { event };\n}" | ||
}, | ||
"Handler": "index.handler", | ||
"Role": { | ||
"Fn::GetAtt": [ | ||
"FServiceRole3AC82EE1", | ||
"Arn" | ||
] | ||
}, | ||
"Runtime": "nodejs18.x" | ||
}, | ||
"DependsOn": [ | ||
"FServiceRoleDefaultPolicy17A19BFA", | ||
"FServiceRole3AC82EE1" | ||
] | ||
}, | ||
"FDynamoDBEventSourcelambdaeventsourcemetricsconfigdynamodbT8ABCAB8CB3F48FC4": { | ||
"Type": "AWS::Lambda::EventSourceMapping", | ||
"Properties": { | ||
"BatchSize": 5, | ||
"EventSourceArn": { | ||
"Fn::GetAtt": [ | ||
"TD925BC7E", | ||
"StreamArn" | ||
] | ||
}, | ||
"FunctionName": { | ||
"Ref": "FC4345940" | ||
}, | ||
"MetricsConfig": { | ||
"Metrics": [] | ||
}, | ||
"StartingPosition": "LATEST" | ||
} | ||
}, | ||
"TD925BC7E": { | ||
"Type": "AWS::DynamoDB::Table", | ||
"Properties": { | ||
"AttributeDefinitions": [ | ||
{ | ||
"AttributeName": "id", | ||
"AttributeType": "S" | ||
} | ||
], | ||
"KeySchema": [ | ||
{ | ||
"AttributeName": "id", | ||
"KeyType": "HASH" | ||
} | ||
], | ||
"ProvisionedThroughput": { | ||
"ReadCapacityUnits": 5, | ||
"WriteCapacityUnits": 5 | ||
}, | ||
"StreamSpecification": { | ||
"StreamViewType": "NEW_IMAGE" | ||
} | ||
}, | ||
"UpdateReplacePolicy": "Delete", | ||
"DeletionPolicy": "Delete" | ||
}, | ||
"F5ServiceRole2E897519": { | ||
"Type": "AWS::IAM::Role", | ||
"Properties": { | ||
"AssumeRolePolicyDocument": { | ||
"Statement": [ | ||
{ | ||
"Action": "sts:AssumeRole", | ||
"Effect": "Allow", | ||
"Principal": { | ||
"Service": "lambda.amazonaws.com" | ||
} | ||
} | ||
], | ||
"Version": "2012-10-17" | ||
}, | ||
"ManagedPolicyArns": [ | ||
{ | ||
"Fn::Join": [ | ||
"", | ||
[ | ||
"arn:", | ||
{ | ||
"Ref": "AWS::Partition" | ||
}, | ||
":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" | ||
] | ||
] | ||
} | ||
] | ||
} | ||
}, | ||
"F5ServiceRoleDefaultPolicyF3745DE6": { | ||
"Type": "AWS::IAM::Policy", | ||
"Properties": { | ||
"PolicyDocument": { | ||
"Statement": [ | ||
{ | ||
"Action": "dynamodb:ListStreams", | ||
"Effect": "Allow", | ||
"Resource": "*" | ||
}, | ||
{ | ||
"Action": [ | ||
"dynamodb:DescribeStream", | ||
"dynamodb:GetRecords", | ||
"dynamodb:GetShardIterator" | ||
], | ||
"Effect": "Allow", | ||
"Resource": { | ||
"Fn::GetAtt": [ | ||
"TD925BC7E", | ||
"StreamArn" | ||
] | ||
} | ||
} | ||
], | ||
"Version": "2012-10-17" | ||
}, | ||
"PolicyName": "F5ServiceRoleDefaultPolicyF3745DE6", | ||
"Roles": [ | ||
{ | ||
"Ref": "F5ServiceRole2E897519" | ||
} | ||
] | ||
} | ||
}, | ||
"F5B560B5F9": { | ||
"Type": "AWS::Lambda::Function", | ||
"Properties": { | ||
"Code": { | ||
"ZipFile": "exports.handler = async function handler(event) {\n console.log('event:', JSON.stringify(event, undefined, 2));\n return { event };\n}" | ||
}, | ||
"Handler": "index.handler", | ||
"Role": { | ||
"Fn::GetAtt": [ | ||
"F5ServiceRole2E897519", | ||
"Arn" | ||
] | ||
}, | ||
"Runtime": "nodejs18.x" | ||
}, | ||
"DependsOn": [ | ||
"F5ServiceRoleDefaultPolicyF3745DE6", | ||
"F5ServiceRole2E897519" | ||
] | ||
}, | ||
"F5DynamoDBEventSourcelambdaeventsourcemetricsconfigdynamodbT8ABCAB8CD0816D3E": { | ||
"Type": "AWS::Lambda::EventSourceMapping", | ||
"Properties": { | ||
"BatchSize": 5, | ||
"EventSourceArn": { | ||
"Fn::GetAtt": [ | ||
"TD925BC7E", | ||
"StreamArn" | ||
] | ||
}, | ||
"FunctionName": { | ||
"Ref": "F5B560B5F9" | ||
}, | ||
"MetricsConfig": { | ||
"Metrics": [ | ||
"EventCount" | ||
] | ||
}, | ||
"StartingPosition": "LATEST" | ||
} | ||
} | ||
}, | ||
"Parameters": { | ||
"BootstrapVersion": { | ||
"Type": "AWS::SSM::Parameter::Value<String>", | ||
"Default": "/cdk-bootstrap/hnb659fds/version", | ||
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" | ||
} | ||
}, | ||
"Rules": { | ||
"CheckBootstrapVersion": { | ||
"Assertions": [ | ||
{ | ||
"Assert": { | ||
"Fn::Not": [ | ||
{ | ||
"Fn::Contains": [ | ||
[ | ||
"1", | ||
"2", | ||
"3", | ||
"4", | ||
"5" | ||
], | ||
{ | ||
"Ref": "BootstrapVersion" | ||
} | ||
] | ||
} | ||
] | ||
}, | ||
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." | ||
} | ||
] | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
....snapshot/lambdaeventsourcedynamodbwithmetricsDefaultTestDeployAssertC1C197C4.assets.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
36 changes: 36 additions & 0 deletions
36
...napshot/lambdaeventsourcedynamodbwithmetricsDefaultTestDeployAssertC1C197C4.template.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.