试图创建一个AMI

问题描述:

的加密拷贝我有以下红宝石代码:试图创建一个AMI

sts = Aws::STS::Client.new 

stsresp = sts.assume_role(
    :role_arn => _role_arn, 
    :role_session_name => "provisioning_vpc_query" 
) 

ec2 = Aws::EC2::Client.new(
    session_token: stsresp.credentials["session_token"], 
    region: _region, 
    access_key_id: stsresp.credentials["access_key_id"], 
    secret_access_key: stsresp.credentials["secret_access_key"] 
) 

# ... 
p "got image: #{preimage_id}, create encrypted copy..." 

resp = ec2.copy_image({ 
    encrypted: true, 
    name: oname, 
    source_image_id: preimage_id, 
    source_region: _region, 
    dry_run: false 
}) 

在上面的代码,preimage_id是在上面提到的区域_region已知的图像。

当我跑,我得到:

"got image: ami-71e9020b, create encrypted copy..." 
Aws::EC2::Errors::InvalidRequest: The storage for the ami is not available in the source region. 

我可以毫无问题控制台手动执行此操作。

你能帮我弄清楚有什么不对吗?

+1

也许'_region'包含无效值? –

+0

更多可能的错误,https://forums.aws.amazon.com/thread.jspa?threadID=246931&tstart=0 – Kannaiyan

事实证明,我试图在它'可用'之前复制ami。添加一行等待诀窍:

sts = Aws::STS::Client.new 

stsresp = sts.assume_role(
    :role_arn => _role_arn, 
    :role_session_name => "provisioning_vpc_query" 
) 

ec2 = Aws::EC2::Client.new(
    session_token: stsresp.credentials["session_token"], 
    region: _region, 
    access_key_id: stsresp.credentials["access_key_id"], 
    secret_access_key: stsresp.credentials["secret_access_key"] 
) 

# ... 
p "got image: #{preimage_id}, create encrypted copy..." 

ec2.wait_until(:image_available, {image_ids: [preimage_id]}) 

resp = ec2.copy_image({ 
    encrypted: true, 
    name: oname, 
    source_image_id: preimage_id, 
    source_region: _region, 
    dry_run: false 
})