AWS lambda: prevent form invocation by S3:TestEvent - amazon-web-services

I have a Lamba triggered by PUT or POST. I made a change of an event notification setting on a bucket and then S3:TestEvent was invoked as it is described in the AWS document. https://docs.aws.amazon.com/AmazonS3/latest/userguide/notification-content-structure.html
When you configure an event notification on a bucket, Amazon S3 sends the following test message.
Is there any way to prevent it? I want to avoid unintentional Lambda executions.

Related

AWS Lambda Moving SES Message to different S3 bucket

In my SES actions I trigger my Lambda function that essentially checks if a message should be blocked. If it is not blocked, it continues processing rules and is put in our "good" email S3 bucket. If it is blocked, it just stops processing and drops the message. I cannot find a way to "block" a message and have it stored in a "bad" email S3 bucket. Though it may not always be the case, being able to review these if required would be ideal. Is this something that can be invoked within the Lambda function or a way to have a workflow within the SES actions?

I want to trigger gitlab-ci pipeline, whenever there is an object put in AWS S3 bucket

I am looking for a way to trigger my gitlab ci pipeline whenever there is a object (with specific name) is added in S3 bucket.
I am new with AWS lambda, can someone please help
You can use s3 event notifications and deliver these events to other AWS services, including AWS Lambda or SQS queues.
Leveraging these event notifications, you could send the event directly to a lambda function that subscribes to putobject events and parses the event content structure to determine if an object of the specific name was created and use the create pipeline API to trigger pipelines on GitLab.
Architecture overview:

Best way to trigger events from incoming SES email

I want to trigger some events based on the body of incoming emails. I see at least two ways of doing this with SES and Lambda, and I'm wondering about the pros and cons.
SES triggers Lambda function. Since SES is only available in a few regions, this means the Lambda function must also be in one of those regions. This passes a JSON object to Lambda containing the headers but not the email content.
SES publishes to SNS, and Lambda function subscribes to the SNS topic. The SNS topic must be in the same region as SES, but the Lambda function can be anywhere. This way the Lambda function receives the full email content, up to maximum size of 150KB.
SES puts the message into S3 bucket, then S3 triggers Lambda. Bucket must be in the same region. This seems overly complex and might take longer because there is an extra call to get the S3 object. There is some potential for error if another user puts objects into the same bucket. This way you can use emails up to 10MB.
Are there any other options or have I gotten anything wrong?
I have gone the SES -> S3 bucket route. I have an S3 event that fires a lambda on create. The lambda then reads the email and moves it to another bucket with a ${emailAddress}/${emailSubject} format as the key and then deletes the original. This allows me to programmatically pull the body based on the email address and subject combination (which is known) in some of my automated tests. Usually, this occurs well within a second. (Today it seems to be running really slow... searching to figure out why which lead me here)

AWS SNS is not invoking lambda function when both are created using Cloudformation template

I have created lambda and SNS using cloudformation. Here first lambda is invoking a SNS which has a subscription of another lambda. Here SNS is supposed to invoke alias of lambda. In SNS topic lambda ARN is showing as subscriber but in lambda it is not added as trigger. There is not a single invocation log of the lambda invoked from SNS. So is this problem about some kind of permission or else ? need help...
Yes, this is a permissions issue. You need to add a permission to the lambda function to allow SNS to invoke it.
Use the AWS::Lambda::Permission resource to add permissions to allow SNS to invoke the lambda function.
I had a heck of a time with one. I had originally set my lambda function to look for an event source of "aws:s3". In order to get the event source from an s3 event, I used "event.Records[0].eventSource". When I tested event.Records[0].eventSource == "aws:sns" to check if my SNS trigger had fired, it wouldn't work. It wasn't until I found sample SNS event JSON that I noticed that SNS events have an event source node of "EventSource". It's capital case. I changed my test to
event.Records[0].EventSource == "aws:sns"
and it worked. So much for consistency in event message formats.

AWS SNS - how to customize the s3 event

I created s3 bucket with event enabled for the bucket. When the new object is uploaded to the bucket sns will trigger an event to lambda to extract content from the file.
Is there any way to customize the sns event in generic format.
There is no out-of-box way to customize the notification format (without involving a middleman like Lambda). I would suggest using AWS Lambda as the direct message destination instead of letting the S3 notification flows through SNS. This AWS documentation will be useful for you (https://docs.aws.amazon.com/AmazonS3/latest/dev/notification-walkthrough-2.html).