2 個答案
- 最新
- 最多得票
- 最多評論
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
已回答 5 年前
相關內容
- AWS 官方已更新 7 個月前
- AWS 官方已更新 1 年前