Điều thú vị đủ, có vẻ như không có nhiều người gặp sự cố này. Đối với tôi rất quan trọng để có thể làm điều này đúng. Nếu không có chức năng này, người dùng không thể truy cập internet từ các trường hợp được đưa vào một số nondefault subnet
.
Tài liệu boto không cung cấp trợ giúp, có lỗi liên quan gần đây đã được sửa, xem tại: https://github.com/boto/boto/pull/1705.
Điều quan trọng cần lưu ý là subnet_id
và bảo mật groups
phải được cung cấp cho giao diện mạng NetworkInterfaceSpecification
thay vì run_instance
.
import time
import boto
import boto.ec2.networkinterface
from settings.settings import AWS_ACCESS_GENERIC
ec2 = boto.connect_ec2(*AWS_ACCESS_GENERIC)
interface = boto.ec2.networkinterface.NetworkInterfaceSpecification(subnet_id='subnet-11d02d71',
groups=['sg-0365c56d'],
associate_public_ip_address=True)
interfaces = boto.ec2.networkinterface.NetworkInterfaceCollection(interface)
reservation = ec2.run_instances(image_id='ami-a1074dc8',
instance_type='t1.micro',
#the following two arguments are provided in the network_interface
#instead at the global level !!
#'security_group_ids': ['sg-0365c56d'],
#'subnet_id': 'subnet-11d02d71',
network_interfaces=interfaces,
key_name='keyPairName')
instance = reservation.instances[0]
instance.update()
while instance.state == "pending":
print instance, instance.state
time.sleep(5)
instance.update()
instance.add_tag("Name", "some name")
print "done", instance
Bất kỳ ai gặp phải lỗi này khi thực hiện việc này? Không thể chỉ định tham số liên kếtPublicIPAddress cho giao diện mạng có ID.' – qwwqwwq
có, rõ ràng là bạn không thể tạo giao diện đầu tiên nữa nếu bạn muốn có IP công khai. Tôi sẽ thêm một câu trả lời cho boto3 phản ánh điều này. [oh chờ đợi, tôi không phải. xem barryku's] –