首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Tag_specifications run_instances() -意外的关键字参数‘Boto’

Tag_specifications run_instances() -意外的关键字参数‘Boto’
EN

Stack Overflow用户
提问于 2020-12-18 20:47:21
回答 2查看 110关注 0票数 0

我正在尝试通过python3脚本在中启动一个aws实例。它工作得很好,但我现在尝试向实例添加一些标签,但没有成功。我正在尝试下面的方法,但得到了一个“意外的关键字参数'tag_specifications'”错误。

代码语言:javascript
复制
import boto.ec2
conn=boto.ec2.connect_to_region("eu-west-1")
conn.run_instances('ami-12345',instance_type='c5.large',key_name='test.prod',
         security_groups=['ProductionInstance'],instance_profile_name='TestProductionProcessor',
         tag_specifications=[{'Key': 'Name','Value': 'TEST'}])

我已经检查了botocore,直到现在,等等。

谢谢

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-12-18 22:57:26

以下代码在Python 3.7上执行成功;

代码语言:javascript
复制
import boto3.ec2

conn=boto3.client('ec2',region_name='eu-west-1')
tags=[
  {'Key':'Name','Value': 'Test'},
]
tag_specification=[{'ResourceType': 'instance','Tags': tags},]
conn.run_instances(ImageId='ami-12345',
                   TagSpecifications=tag_specification,
                   InstanceType='c5.large',
                   SecurityGroupIds=['sg-12345'], #change value of SecurityGroupIds as per your setup
                   IamInstanceProfile={
                     'Name': 'TestProductionProcessor'
                   },
                   MaxCount=1,
                   MinCount=1,
                   SubnetId='subnet-12345' #change value of SubnetId as per your setup
                   )
票数 0
EN

Stack Overflow用户

发布于 2020-12-18 21:51:41

您可以使用以下命令尝试

代码语言:javascript
复制
TagSpecifications=[
        {
            'ResourceType': 'instance',
            'Tags': [
                {
                    'Key': 'Name',
                    'Value': 'Test'
                },
            ]
        }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65357345

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档