Disable Source/Destination Check AWS Python Boto

痴心易碎 提交于 2020-01-17 08:41:07

问题


I am trying to automate deployment of a aws VPN [IPSec] instance using python boto. I am launching new instance using, '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])

For this script to work, I need to disable source/destination check for this instance. I couldn't find a way to disable this using python boto. As per the boto documentation I can do this using 'modify_instance_attribute'.

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

However I couldn't find any sample script using this attribute. Please give me some examples so that I can complete this.

Thanks in advance.


回答1:


From boto3 documentation the way you would do this is:

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:


You would have to use the modify_instance_attribute method after you have launched the instance with run_instances. Assuming your call to run_instances returns a single instance:

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


来源:https://stackoverflow.com/questions/26139271/disable-source-destination-check-aws-python-boto

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!