[英]how to assign an ip address to an ec2 instance using the v2 ruby sdk
創建實例后,如何使用 v2 ruby sdk 為 ec2 實例分配 IP 地址。
我試過
ec2.associate_address()
方法(在http://docs.aws.amazon.com/sdk-for-ruby/v2/developer-guide/ec2-using-elastic-ip-addresses.html 中提到)但這似乎是一種 v1 方法
這是帶有 aws Ruby SDK v1 的 Ruby 代碼。 我正在獲取彈性 IP 的分配 ID 並將其傳遞給實例對象的 associate_elastic_ip 方法。
require 'aws-sdk-v1'
require 'json'
temp_ec2 = AWS::EC2.new
instance = temp_ec2.instances["i-8392ld62828f0c97"]
elasticIp = AWS::EC2::ElasticIp.new("49.234.122.12")
if elasticIp.exists?
begin
instance.associate_elastic_ip(elasticIp.allocation_id)
puts "[Success]EIP has been associated successfully...."
rescue Exception => e
puts "There is an exception in allocating elastic ip and the exception is..#{e}"
end
else
puts "[Failed]EIP doesn't exist in the account."
end
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.