-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathexample-pattern.json
More file actions
74 lines (74 loc) · 3.77 KB
/
example-pattern.json
File metadata and controls
74 lines (74 loc) · 3.77 KB
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
{
"title": "Lambda with S3 Failed-Event Destination and Athena Analytics",
"description": "Capture Lambda failed events to S3 and analyze them with Athena for error insights and patterns using asynchronous invocations.",
"language": "TypeScript",
"level": "200",
"framework": "AWS CDK",
"introBox": {
"headline": "How it works",
"text": [
"This pattern demonstrates how to use Amazon S3 as a failed-event destination for AWS Lambda asynchronous invocations.",
"A Lambda function implements business logic with success and failure scenarios.",
"When Lambda fails during asynchronous invocation, AWS automatically captures the failed event to S3 for analysis.",
"Amazon Athena with AWS Glue enables SQL-based analytics on failed events to identify error patterns and gain insights.",
"The pattern uses AWS CLI with --invocation-type Event to demonstrate asynchronous invocation.",
"Important: Lambda destinations only work with asynchronous invocations (S3, SNS, EventBridge) and stream-based sources (Kinesis, DynamoDB Streams, SQS). They do not trigger for synchronous invocations."
]
},
"gitHub": {
"template": {
"repoURL": "https://github.com/aws-samples/serverless-patterns/tree/main/lambda-s3-athena-cdk-ts",
"templateURL": "serverless-patterns/lambda-s3-athena-cdk-ts",
"projectFolder": "lambda-s3-athena-cdk-ts",
"templateFile": "lib/pattern-stack.ts"
}
},
"resources": {
"bullets": [
{
"text": "AWS Lambda S3 Failed-Event Destination Announcement",
"link": "https://aws.amazon.com/about-aws/whats-new/2024/11/aws-lambda-s3-failed-event-destination-stream-event-sources/"
},
{
"text": "AWS Lambda Destinations Documentation",
"link": "https://docs.aws.amazon.com/lambda/latest/dg/invocation-async.html#invocation-async-destinations"
},
{
"text": "Amazon Athena Documentation",
"link": "https://docs.aws.amazon.com/athena/latest/ug/what-is.html"
},
{
"text": "AWS Glue Data Catalog",
"link": "https://docs.aws.amazon.com/glue/latest/dg/catalog-and-crawler.html"
}
]
},
"deploy": {
"text": [
"Clone the repository: <code>git clone https://github.com/aws-samples/serverless-patterns</code>",
"Change directory: <code>cd lambda-s3-athena-cdk-ts</code>",
"Install dependencies: <code>npm install</code>",
"Deploy the CDK stack: <code>cdk deploy</code>"
]
},
"testing": {
"text": [
"Get Lambda function name: <code>FUNCTION_NAME=$(aws cloudformation describe-stacks --stack-name LambdaS3AthenaCdkStack --query 'Stacks[0].Outputs[?OutputKey==`LambdaFunctionName`].OutputValue' --output text)</code>",
"Test successful request: <code>aws lambda invoke --function-name $FUNCTION_NAME --invocation-type Event --payload '{\"action\": \"process\", \"value\": 10}' response.json</code>",
"Test failed request: <code>aws lambda invoke --function-name $FUNCTION_NAME --invocation-type Event --payload '{\"action\": \"process\", \"value\": -5}' response.json</code>",
"Verify failed events in S3: <code>aws s3 ls s3://$(aws cloudformation describe-stacks --stack-name LambdaS3AthenaCdkStack --query 'Stacks[0].Outputs[?OutputKey==`FailedEventsBucketName`].OutputValue' --output text)/ --recursive</code>",
"Query errors with Athena: <code>SELECT responsepayload.errortype, COUNT(*) FROM failed_events GROUP BY responsepayload.errortype;</code>"
]
},
"cleanup": {
"text": ["Delete the stack: <code>cdk destroy</code>"]
},
"authors": [
{
"name": "Marco Jahn",
"image": "https://sessionize.com/image/e99b-400o400o2-pqR4BacUSzHrq4fgZ4wwEQ.png",
"bio": "Senior Solutions Architect, Amazon Web Services",
"linkedin": "marcojahn"
}
]
}