繁体   English   中英

AWS boto3 在创建 AMI 后无法放置标签

[英]AWS boto3 unable to put tags after creating an AMI

我正在尝试在使用 boto3 从实例创建 AMI 并收到错误后放置标签:

botocore.exceptions.ParamValidationError:参数验证失败:输入中的未知参数:“TagSpecifications”,必须是以下之一:BlockDeviceMappings、Description、DryRun、InstanceId、Name、NoReboot

这是我的代码,你能检查一下我做错了什么吗?

它适用于快照但不适用于图像。

import xlrd
import boto3
import datetime

client = boto3.client('ec2')


# Give the location of the file
loc = ("/Users/user1/Documents/aws-python/aws-tag-test (1).xlsx")

# To open Workbook
wb = xlrd.open_workbook(loc)
sheet = wb.sheet_by_index(0)

# For row 0 and column 0
#print (sheet.cell_value(0, 0))

nowtime = datetime.datetime.now()
nowdate = (nowtime.strftime("%Y-%m-%d %H-%M"))
print (nowdate)

#print (nowtime)

server_ids = []
instancename =[]
for i in range (1,sheet.nrows):
    server_ids.append(sheet.cell_value(i,1))
    instancename.append(sheet.cell_value(i,0))


    #print (sheet.cell_value(i,1))
# excel closed

for i in range (len(server_ids)):
    print(server_ids[i], instancename[i])
    response = client.create_image(
        Description     = 'ami ' + instancename[i] + ' ' + str(nowdate),
        InstanceId      = server_ids[i],
        Name            = 'ami ' + instancename[i] + ' ' + str(nowdate),
        NoReboot        = True,
        DryRun=False,
        TagSpecifications=[
            {
                'ResourceType': 'image',
                'Tags': [
                    {
                        'Key': 'Name',
                        'Value': 'ami-' + instancename[i] + '-' + str(nowdate)
                    },
                    {
                        'Key': 'date',
                        'Value': datetime.datetime.now().strftime("%Y-%m-%d")
                    }
                ]
            },
        ]
)
#)


print(response)

真的很感谢你的帮助。

是的,它现在可用。 不知道什么时候,但它肯定是在原始评论之后的某个时间添加的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM