【问题标题】:Disable Source/Destination Check AWS Python Boto禁用源/目标检查 AWS Python Boto
【发布时间】:2017-02-07 00:06:51
【问题描述】:

我正在尝试使用 python boto 自动部署 aws VPN [IPSec] 实例。我正在使用“ec2.run_instances”启动新实例。

reservations = ec2.run_instances(
image_id,
subnet_id=subnet_id,
instance_type=instance_type,
instance_initiated_shutdown_behavior='stop',
key_name=key_name,
security_group_ids=[security_group])

为了使该脚本正常工作,我需要为此实例禁用源/目标检查。我找不到使用 python boto 禁用它的方法。根据 boto 文档,我可以使用“modify_instance_attribute”来做到这一点。

http://boto.likedoc.net/en/latest/ref/ec2.html

但是我找不到任何使用此属性的示例脚本。请给我一些例子,以便我完成这个。

提前致谢。

【问题讨论】:

  • ec2 = boto.ec2.connection.EC2Connection(region=regon) ec2.modify_instance_attribute(instance.id, 'sourceDestCheck', 'false', dry_run=False)
  • 上面给出的代码对我有用

标签: boto


【解决方案1】:

来自boto3 documentation,您这样做的方式是:

response = requests.get('http://169.254.169.254/latest/meta-data/instance-id')
instance_id = response.text
ec2_client = boto3.client('ec2')
result = ec2_client.modify_instance_attribute(InstanceId=instance_id, SourceDestCheck={'Value': False})

【讨论】:

    【解决方案2】:

    在使用run_instances 启动实例后,您必须使用modify_instance_attribute 方法。假设您对run_instances 的调用返回一个实例:

    instance = reservations[0].instances[0]
    ec2.modify_instance_attribute(instance.id, attribute='sourceDestCheck', value=False)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-13
      相关资源
      最近更新 更多