【问题标题】:How to query AWS using boto3 to find if the IMDSv2 is enforced in an EC2 instance or not如何使用 boto3 查询 AWS 以查找 IMDSv2 是否在 EC2 实例中实施
【发布时间】:2021-04-15 22:22:04
【问题描述】:

boto3 中是否有任何函数可以判断 IMDSV2 是否启用?

【问题讨论】:

    标签: amazon-web-services amazon-ec2 boto3


    【解决方案1】:
    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)
    

    【讨论】:

      猜你喜欢
      • 2016-07-29
      • 1970-01-01
      • 2020-09-30
      • 2021-05-09
      • 2018-06-18
      • 1970-01-01
      • 2023-03-29
      • 1970-01-01
      • 2017-08-11
      相关资源
      最近更新 更多