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公式更新しました 1年前