Here is one way to write your AWS Lambda function:
import boto3 def lambda_handler(event, context): INSTANCE_ID = 'i-05c69a91775e1258b' TARGET_ARN = 'arn:aws:sns:us-east-1:xxxxxxxx:MyEmailTopic' ec2_client=boto3.client('ec2') sns_client=boto3.client('sns') instances = ec2_client.describe_instance_status(InstanceIds=[INSTANCE_ID]) instance_state = instances["InstanceStatuses"]["InstanceState"]["Name"] if(instance_state=="running"): response = sns_client.publish( TargetArn=TARGET_ARN, Message="The " + INSTANCE_ID + " instance is up and running" ) else: print("failed to get status") return ''
Hope this helps!
That has worked perfectly! Thank you very much.
How to read DynamoDB table using aws lambda function in python?asked 5 months ago
I need your help with Putty
I Can't send a email with my AWS accountasked 5 months ago
A lambda function to delete old archive files in s3 bucketasked 3 years ago
Why am I not able to create alerts and set alert thresholds?asked 2 months ago
I need your help with EC2 - Network error: software caused connection abort
Can I not run Xen hypervisor in a bare-metal instance?asked 8 months ago
Help with AWS Lambda function to send notificationsAccepted Answerasked 3 years ago
How do I get trigger broker topic's routing key on lambda functionasked 4 months ago
Hello guys , help me to setup load balancerasked 8 days ago