S3 event notification body content - amazon-web-services

I've configured an event notification on an AWS s3 bucket, putting a message on an SQS queue.
The body of that event contains an array of records.
I would like to understand in which conditions there are multiple records in the body.
Is it when we upload files immediately after each other?
Or only when uploading multiple files at once?
So is this generated on a time basis, collecting all the requests in X amount of time and sending a message to SQS, or is it a separate event for each request to the bucket?

There are different ways you can find S3 Event message structure;
This is document from AWS with Event message structure.
To get specific S3 Event message structure, you can go for one of following practical approach;
You can enable AWS cloud-trail logs. Then, perform some events on related AWS S3 bucket, afterwards view S3 events using the AWS cloudtrail Event history or Insights based on your AWS S3 bucket.
Use a simple AWS lambda mapped to your AWS S3 events, which will just print the AWS S3 events associated with your S3 bucket.

Related

AWS S3 File Push to FTP or SFTP Server

is there a way to push newly uploaded file from S3 to an FTP or SFTP server within AWS Services?
my s3 looks something like this:
s3-bucket/some_path/yyyymm/yyyymmdd/file_yyymmdd.csv.gz
and everytime we generate a new file based on date, we need to upload or transfer to FTP server
You can have S3 send event notifications to other AWS services when a new object is uploaded to a bucket.
You could have that trigger a Lambda function each time a new object is uploaded. The Lambda function would receive an event object with information about the S3 bucket and the path of the object in the bucket. It can use that info to download the file from S3, and upload it to an FTP server.
I would recommend having S3 send the events to an SQS queue, and having your Lambda function pull events from the queue, that way you have both built-in error handling, and concurrency throttling of your Lambda function invocations.
If you don't want to use a Lambda function for this, you could have S3 send the events to SQS, and then run some code that polls SQS anywhere, such as on an EC2 server, or in an ECS task.

AWS S3 Event Notification for upload start

I have tried setting up S3 event notifications via SNS topic & was able to successfully get event notifications when objects are created. However in my use case we have large file uploads from the apps that we don't control. These uploads take time. We want to get notified when upload starts (in progress) as well.
I was not able to find any event type that corresponds to upload start!
For large files multipart uploads are used so we get "multipart upload complete" event but still we don't have a clue about when the upload started!
Is there any other way to detect the uploads (start) on AWS S3?
You can create an Amazon CloudWatch Events rule that triggers on CreateMultiPartUpload and sends a message to an Amazon SNS topic:
From CreateMultipartUpload - Amazon Simple Storage Service:
This action initiates a multipart upload and returns an upload ID.

Want to fetch all image name which is uploaded to s3 and process them in Lambda

I am trying to setup AWS Rekognition using lambda so i have created s3 event trigger for each image uploaded to s3 so when a new image uploaded to s3 it will send an SNS notification > SNS will send to SQS > SQS will trigger lambda to process on that image.
MY main question is how i pass the uploaded Object key name to lambda? if anyone knows or having any idea please let me know
I'am not sure why you are using SNS and SQS to reach to lambda from S3.
You can directly link S3 event to Lambda.You can filter the event to PUT/POST/DEL etc too.This is best approach, instead of using SNS and SQS in between.
S3 event pretty much has all the data required to process.
You may look at
https://docs.aws.amazon.com/lambda/latest/dg/with-s3.html
https://docs.aws.amazon.com/lambda/latest/dg/with-s3-example.html

is long polling in aws s3 available?

I have a node.js backend that sends out images to a secondary api for transformations and then those images appear in s3 bucket. The problem is that the secondary api doesn't inform my api when the file is created in the bucket.
Is there some sort of long polling in s3 available because spamming get requests doesn't feel right (also will get expensive).
I'm considering adding a trigger on new files in s3, that will invoke a lambda that will put a message into some sort of pub/sub message broker and then I could just subscribe to it but this seems a bit too complicated?
From the S3 notification docs you can be notified via:
Amazon Simple Notification Service (Amazon SNS) topic
Amazon Simple Queue Service (Amazon SQS) queue
AWS Lambda
The relative benefits or each one are up to you but don't poll S3 for changes. Use one of these to be notified of the changes. You can decide to get notices for just new objects or deleted object.

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).