Skip to content

Commit 704b1da

Browse files
authored
Add final pattern file
1 parent b03e313 commit 704b1da

1 file changed

Lines changed: 106 additions & 0 deletions

File tree

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
{
2+
"title": "AWS Lambda Failed-Event Destination and Amazon Athena Analytics",
3+
"description": "Capture AWS Lambda failed events to Amazon S3 and analyze them with Amazon Athena for error insights and patterns using asynchronous invocations.",
4+
"language": "TypeScript",
5+
"level": "200",
6+
"framework": "AWS CDK",
7+
"introBox": {
8+
"headline": "How it works",
9+
"text": [
10+
"This pattern demonstrates how to use Amazon S3 as a failed-event destination for AWS Lambda asynchronous invocations.",
11+
"A Lambda function implements business logic with success and failure scenarios.",
12+
"When the Lambda function fails during asynchronous invocation, AWS automatically captures the failed event to S3 for analysis.",
13+
"Amazon Athena with AWS Glue enables SQL-based analytics on failed events to identify error patterns and gain insights.",
14+
"The pattern uses AWS CLI with --invocation-type Event to demonstrate asynchronous invocation.",
15+
"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."
16+
]
17+
},
18+
"gitHub": {
19+
"template": {
20+
"repoURL": "https://github.com/aws-samples/serverless-patterns/tree/main/lambda-s3-athena-cdk-ts",
21+
"templateURL": "serverless-patterns/lambda-s3-athena-cdk-ts",
22+
"projectFolder": "lambda-s3-athena-cdk-ts",
23+
"templateFile": "lib/pattern-stack.ts"
24+
}
25+
},
26+
"resources": {
27+
"bullets": [
28+
{
29+
"text": "AWS Lambda S3 Failed-Event Destination Announcement",
30+
"link": "https://aws.amazon.com/about-aws/whats-new/2024/11/aws-lambda-s3-failed-event-destination-stream-event-sources/"
31+
},
32+
{
33+
"text": "AWS Lambda Destinations Documentation",
34+
"link": "https://docs.aws.amazon.com/lambda/latest/dg/invocation-async.html#invocation-async-destinations"
35+
},
36+
{
37+
"text": "Amazon Athena Documentation",
38+
"link": "https://docs.aws.amazon.com/athena/latest/ug/what-is.html"
39+
},
40+
{
41+
"text": "AWS Glue Data Catalog",
42+
"link": "https://docs.aws.amazon.com/glue/latest/dg/catalog-and-crawler.html"
43+
}
44+
]
45+
},
46+
"deploy": {
47+
"text": [
48+
"Clone the repository: <code>git clone https://github.com/aws-samples/serverless-patterns</code>",
49+
"Change directory: <code>cd lambda-s3-athena-cdk-ts</code>",
50+
"Install dependencies: <code>npm install</code>",
51+
"Deploy the CDK stack: <code>cdk deploy</code>"
52+
]
53+
},
54+
"testing": {
55+
"text": [
56+
"Get Lambda function name: <code>FUNCTION_NAME=$(aws cloudformation describe-stacks --stack-name LambdaS3AthenaCdkStack --query 'Stacks[0].Outputs[?OutputKey==`LambdaFunctionName`].OutputValue' --output text)</code>",
57+
"Test successful request: <code>aws lambda invoke --function-name $FUNCTION_NAME --invocation-type Event --payload '{\"action\": \"process\", \"value\": 10}' response.json</code>",
58+
"Test failed request: <code>aws lambda invoke --function-name $FUNCTION_NAME --invocation-type Event --payload '{\"action\": \"process\", \"value\": -5}' response.json</code>",
59+
"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>",
60+
"Query errors with Athena: <code>SELECT responsepayload.errortype, COUNT(*) FROM failed_events GROUP BY responsepayload.errortype;</code>"
61+
]
62+
},
63+
"cleanup": {
64+
"text": [
65+
"Delete the stack: <code>cdk destroy</code>"
66+
]
67+
},
68+
"authors": [
69+
{
70+
"name": "Marco Jahn",
71+
"image": "https://sessionize.com/image/e99b-400o400o2-pqR4BacUSzHrq4fgZ4wwEQ.png",
72+
"bio": "Senior Solutions Architect, Amazon Web Services",
73+
"linkedin": "marcojahn"
74+
}
75+
],
76+
"patternArch": {
77+
"icon1": {
78+
"x": 20,
79+
"y": 50,
80+
"service": "lambda",
81+
"label": "AWS Lambda"
82+
},
83+
"icon2": {
84+
"x": 55,
85+
"y": 50,
86+
"service": "s3",
87+
"label": "Amazon S3"
88+
},
89+
"icon3": {
90+
"x": 80,
91+
"y": 50,
92+
"service": "athena",
93+
"label": "Amazon Athena"
94+
},
95+
"line1": {
96+
"from": "icon1",
97+
"to": "icon2",
98+
"label": "Failed-event destination"
99+
},
100+
"line2": {
101+
"from": "icon2",
102+
"to": "icon3",
103+
"label": "analyze"
104+
}
105+
}
106+
}

0 commit comments

Comments
 (0)