boto3中有没有可以判断IMDSV2是否启用的函数?
发布于 2021-04-15 22:22:04
import boto3
ec2 = boto3.client('ec2')
instance_id = 'i-xxx'
res = ec2.describe_instances(InstanceIds=[instance_id])
metadata_options = res['Reservations'][0]['Instances'][0]['MetadataOptions']
http_tokens = metadata_options['HttpTokens']
state = metadata_options['State']
if http_tokens == 'required' and state == 'applied':
print(f"IMDSv2 is enforced in the EC2 instance with id {instance_id}")
else:
print(f"IMDSv2 is not enforced")
print(http_tokens, state)https://stackoverflow.com/questions/67109314
复制相似问题