Prerequisites
- AWS console access
- S3 bucket
- Two Amazon SNS
- Lambda configuration
Overview
SNS
Step 1: Create first SNS
- Add SNS policy
{
"Version": "2012-10-17",
"Id": "sns-ID",
"Statement": [
{
"Sid": "Example SNS topic policy",
"Effect": "Allow",
"Principal": {
"Service": "s3.amazonaws.com"
},
"Action": "SNS:Publish",
"Resource": "SNS-topic-ARN", #arn of thie created sns
"Condition": {
"StringEquals": {
"aws:SourceAccount": "426857564226"
},
"ArnLike": {
"aws:SourceArn": "arn:aws:s3:::prashansa-sns-bucket"
}
}
}
]
}
*Step 2: * Go to subscription and click on create subscription
- Create subscription setting protocol as AWS Lambda that means the destination of this SNS is AWS Lambda.
Step 3: Create another SNS
- Another SNS for notifying user via email
- Set policy for this SNS
*Step 4: * Create subscription
- Set the protocol to email for this SNS to send direct notification to the user via email
S3 Bucket
*Step 5: * Create S3 bucket
Step 6: Go to properties > event notification > create event notification
Step 7: Go to Destination
- Scrolling down there is destination
Lambda
Step 8: Create lambda function
Step 9: Add trigger
- Add the first SNS whose protocol was set to lambda as trigger
Step 10: Set Lambda destination
- In the lambda destination, set the SNS secondly created that was set the protocol for email as the lambda destination
Testing
Step 11: Upload the image in S3 bucket
Step 12: Check the email for notification
References
https://repost.aws/knowledge-center/lambda-invoke-error-s3-bucket-permission