
Capture AWS Lambda failed events to Amazon S3 and analyze them with Amazon Athena for error insights and patterns using asynchronous invocations.
git clone https://github.com/aws-samples/serverless-patterns/cd serverless-patterns/lambda-s3-athena-cdk-tsClone 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>FUNCTION_NAME=$(aws cloudformation describe-stacks --stack-name LambdaS3AthenaCdkStack --query 'Stacks[0].Outputs[?OutputKey==`LambdaFunctionName`].OutputValue' --output text)aws lambda invoke --function-name $FUNCTION_NAME --invocation-type Event --payload '{"action": "process", "value": 10}' response.jsonaws lambda invoke --function-name $FUNCTION_NAME --invocation-type Event --payload '{"action": "process", "value": -5}' response.jsonaws s3 ls s3://$(aws cloudformation describe-stacks --stack-name LambdaS3AthenaCdkStack --query 'Stacks[0].Outputs[?OutputKey==`FailedEventsBucketName`].OutputValue' --output text)/ --recursiveSELECT responsepayload.errortype, COUNT(*) FROM failed_events GROUP BY responsepayload.errortype;cdk destroy