Jupiterese
Jupiterese

Reputation: 151

Subscribe to S3 bucket notifications SNS Topic directly on EC2 instance

I'd like to subscribe to a S3 bucket notifications SNS Topic directly on an EC2 instance where I have a script running that's listening for a S3 bucket update event.

I assume I need to do:

aws sns subscribe --topic-arn [ARN of S3 bucket update topic] --protocol [email, email-json, http, https, or sqs]

What protocol would make sense in this context?

Upvotes: 3

Views: 2690

Answers (1)

Frederic Henri
Frederic Henri

Reputation: 53793

To answer your question, you would need to have an endpoint on your ec2 instance that can receive and process the messages from SNS so the protocol would be http or https (depending how you setup the server on your ec2 instance). You can read more about this in Sending Amazon SNS Messages to HTTP/HTTPS Endpoints

Note sure how you wrote your script but if its using python/java/javascript or anything that can be supported by lambda it would be much better to deploy your code in a lambda function and have the message sent to this lambda, you only pay when its executed (in the other case, your ec2 instance needs to be always up and running to listen to messages). lambda is a supported protocol of sns subscription

A third option is to introduce SQS in the picture, you will run in asynchronous mode (depends on your requirement if its an option or not) you would choose sqs as the protocol value of your SNS message (read Sending Amazon SNS Messages to Amazon SQS Queues for more info) and you would need your ec2 webservice to pick the message in sqs queue

Upvotes: 2

Related Questions