METADATA_URL = "http://169.254.169.254/latest/"
def is_aws_instance():
try:
token = requests.put(
METADATA_URL + "api/token",
headers={"X-aws-ec2-metadata-token-ttl-seconds": "3600"}
).text
metadata = requests.get(
METADATA_URL + "meta-data/",
headers={"X-aws-ec2-metadata-token": token}
)
return str(metadata.status_code) == '200'
except requests.RequestException:
return False
if is_aws_instance():
print("This instance is running on AWS.meta=")
else:
print("This instance is not running on AWS.meta=")
0 件のコメント:
コメントを投稿