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 공식업데이트됨 일 년 전