AWS S3 Event Notifications API - amazon-web-services

I'm trying to find a way using the AWS SDK API to grab the current contents of the event notifications block. This Event Notifications is under an S3 bucket and is dynamic with how many notifications there are. I want a way to send a request, have it return a list with the current notifications so I can verify that it's working through an automated test. I'm not sure how to do this currently via the API so any help would be appreciated!
Workflow: Javascript GET Request > S3 Bucket Event Notifications > Returns list of all event notifications tied to this bucket
[Example Picture of the Event Notifications contains a message][1]
[1]: https://i.stack.imgur.com/UGJgK.png

Related

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:

Aws S3 event notification mail for différent user

we have an aws account with some s3 buckets that are used by several people. I would like to know if there is a way, and if so which ones, to configure an sns notification by email when a restore from s3 glacier deep archive is completed so that this email goes to the person who initiated the retrieval ?
Yes, there in fact there are multiple ways to accomplish this. What you would want to do is to create an Event Notification for your bucket. This can be found in the console by going into the bucket Properties and pressing the Create Event Notification button.
You will be prompted to select the type of action for which you want to send notifications. You would want to select s3:ObjectRestore:Completed:
You will need destination for your events. For sending emails, one option would be to create an SNS topic and use that as a destination. This topic can be integrated with Amazon Simple Email Service (SES) which will be able to send mails.
Other option would be to select a Lambda function as destination and use that to send emails and do other automations.
the problem is more, how as an admin can I configure the sending of mail to the user who initiated the restoration and only to him
In this case you would want to enable Event Bridge integration for your bucket. If you enable it, it will send events which contain requester who initiated the restore for an object (see event full event format here). Event Bridge can be also integrated with SNS or Lambda.

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.

S3 event notification body content

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.

Get Notified when upload is completed in Amazon S3 bucket

Is there a way by which I can get notified when a upload is completed in S3 Bucket? The requirement is that I need to provide link to users after uploading of a video is complete in the bucket. By default now I provide link after 30 minutes of start of video, whether video takes 5 minutes to upload or 40 minutes. So is there any way like any API that provides information that the upload has been completed?
Notifications can be triggered in Amazon S3 when any of the following occur:
s3:ObjectCreated:*
s3:ObjectCreated:Put
s3:ObjectCreated:Post
s3:ObjectCreated:Copy
s3:ObjectCreated:CompleteMultipartUpload
s3:ObjectRemoved:*
s3:ObjectRemoved:Delete
s3:ObjectRemoved:DeleteMarkerCreated
s3:ReducedRedundancyLostObject
Notifications can be sent via three destinations:
Amazon Simple Notification Service (SNS), which in-turn can send notifications via email, HTTP/S endpoint, SMS, mobile push notification
Amazon Simple Queueing Service (SQS)
Amazon Lambda (not currently available in all regions)
See: Configuring Amazon S3 Event Notifications
The most appropriate choice depends on your programming preference and how your app is written:
Use SNS to push to an HTTP endpoint to trigger some code in your app
Write some code to periodically check an SQS queue
Write a Lambda function in Node.js or Java
Once triggered, your code would then need to identify who uploaded the video, retrieve their user details, then send them an email notification. This would be easiest if you control the key (filename) of the object being uploaded, since this will assist in determining the user to notify.
You can use Amazon Lambda to post a message to Amazon SNS (or notify you any other way) when a file is uploaded to S3.
Setup an S3 trigger to your Lambda function. See this tutorial: http://docs.aws.amazon.com/lambda/latest/dg/walkthrough-s3-events-adminuser.html
Inside your Lambda function, send out your notification. You can use SNS, SES, SQS, etc.
There is no direct method that can tell that whether the upload is complete or not in S3 bucket. You can do a simple thing which I have followed after lot of research and it is working correctly.
Follow this link and read the size of file after every 30 seconds or so as per your requirement when the file size has not changed for two simultaneous readings once again check the size for surety because it might be due to network congestion that size might not have changed for two simultaneous readings.