2 Answers
- Newest
- Most votes
- Most comments
0
Hi,
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"][0]["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!
-randy
answered 5 years ago
Relevant content
- asked 4 years ago
- asked 6 months ago
- AWS OFFICIALUpdated 7 months ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 3 years ago
- AWS OFFICIALUpdated a year ago