Hello Readers, In this blog we’re going to learn How to configure AmazonEvent Bridge for ec2 state and we’re going to do this by Amazon SNS for that specifically, I’m going to cover
How we can get an email notification every time the ec2 instance state will change.
Using an event bridge rule and if you want to Schedule a Lambda Function using Amazon EventBridge click here.
Create an ec2 machine:
I’ve created an ec2 machine using the AWS console of ubuntu but the region should be matched with Amazon eventbridge rule and SNS regions also. except for the default, for the subnet choose a specific zone and leaves the other settings default.
Create SNS topic:
After that, we’re going to create SNS topic which is going to be the target for our event rule in the event bridge.
- Click create topic
- Type standard
- Click createtopic
We’ve created SNS topic now I’m going to enable an email subscription to this topic anytime an event happens. scroll down to the subscription.
- Click createsubscription
- Leave the other settings to default
So before we can get notifications we need to confirm my email address. for that check your mailbox and click confirm subscription.
Alright, the status is confirmed.
Create EventBridge rule:
Next, create the rule and give it a name and for pattern, it’s a rule with an event pattern because it’s coming from an ec2 event. Click next and scroll down and follow the settings for the Event pattern as mentioned in the image.
After that, click next and for selecting target check the below image:
You may verify the settings for the review and create by following images.
So I’ve stopped the ec2 instance and tada got the email regarding that.
And if I restart the ec2 instance I’ll have the starting email also even for pending and running state.
Conclusion:
Therefore, In this article, we’ve seen how we can configure the Amazon EventBridge by SNS to get an email for the states of the ec2 machine and it depends on the event type you’ll get the notification as per the selected event.