Email notification using SNS topic and Lambda function in AWS

0 votes

I have my instances in AWS. I want to set notification system when my instance will stop automatically.

How can I do that?

Thank You

Apr 2, 2020 in AWS by akhtar
• 38,260 points
4,650 views

1 answer to this question.

0 votes

Hi@akhtar,

You can set notification system for your instances. You can use SNS topic and Lambda function to do that.

  • Launch an EC2 instance.

  • Create one SNS topic.

  • Create IAM Role for Lambda to access SNS topic and CloudWatch logs.

  • Create Cloudwatch events to schedule.

  • Use below lambda code. 

import json
import boto3
client = boto3.client('sns')
def lambda_handler(event, context):
    topic_arn = 'arn:aws:sns:us-west-1:074796737877:Notification'
    message = 'Instance stop please look on'
    client.publish(TopicArn=topic_arn,Message=message)
    # TODO implement
    return {
        'statusCode': 200,
        'body': json.dumps('Hello from Lambda!')
    }

Hope this will help.

Thank You

answered Apr 2, 2020 by MD
• 95,460 points

Related Questions In AWS

0 votes
1 answer
0 votes
0 answers
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
3 answers

How to check instance state and status via Lambda function in AWS?

import boto3 from pprint import pprint def lambda_handler(event, context):          # ...READ MORE

answered Sep 8, 2020 in AWS by Shrikant
• 180 points
10,445 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP