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 in AWS by akhtar
• 10,580 points
220 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 by MD
• 23,050 points

Related Questions In AWS

0 votes
1 answer
0 votes
0 answers
+1 vote
3 answers

Log in to AWS using Access Key ID and Secret Access Key ID

Access keys consist of an access key ...READ MORE

answered Aug 17, 2018 in AWS by Priyaj
• 57,530 points
6,070 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer