Amazon Web Services – Amazon S3 Notifications to SNS
In this article, we will see how the Amazon S3 bucket publishes notifications to SNS topics on object creation events. An object that creates an event is of four types. They are Put, Post, Copy, Multipart Upload, Remove, Replicate and Restore. Thus, whenever any of the event occur in our S3 bucket, it will publish a notification to a topic and the subscribers to that topic can view those messages.
Approach:
- Create an SNS topic, say, BeginnerTopic.
- Create subscribers under the topic.
- Create an S3 bucket, say, w3wiki.
- Create event notifications under that bucket and configure them to the created topic.
- Upload object in the bucket.
- View message received by the subscriber.
The above approach has been implemented below.
- Creation of SNS topic: SNS topic could be of two types, FIFO (First in First Out) and Standard. We will choose a standard for now and give the name as BeginnerTopic. We will keep the encryption of messages disabled. Under access policy, by default only the owner is allowed to publish messages to the topic, not even the AWS services are allowed. Therefore, we select Basic and can opt either Everyone or Only the specified AWS accounts (need to specify the AWS account number). We will go for everyone and keep the rest of the settings as default and create the topic. See the below images:
- Create Subscriber to Topic: A subscriber can subscribe to the topic in many ways. Some of the ways are Email, SMS, HTTPS, etc. We will select the email in this demo and under the endpoint will specify the email to which we want to receive messages. Leave the rest of the settings as default and create a subscriber. Once the subscriber is created, confirm the subscription to the topic by email received on your email id. See the below images:
- Create a Bucket: Create a bucket in which when an object creates an event occurs, it should trigger an event and publish a notification to the topic. See the below image:
- Create Event Configuration: To create events, go to the properties of the bucket and click on create event notifications tab. Specify the event name, say, Beginnereventtest, select event type as All object create event and under destination, select SNS Topic and choose the topic BeginnerTopic. Click save changes. Once the event is created, you will receive an email stating TestEvent, thus confirming your subscription to the topic. See the below images:
- Upload Object: Upload an object in the bucket to trigger an event. The event type will be of Put type as you are putting the object into the bucket.
- Confirm event notification – As soon as the object is uploaded, an event is triggered, and it publishes the messages to the topic to which event has been configured. In our case BeginnerTopic. To confirm, view the message received in the email. See the below image:
We have successfully configured an event to SNS and are able to view messages through subscribers.
Contact Us