ane*_*ari 3 python amazon-ec2 amazon-web-services boto3
这是我的代码。这段代码有问题吗?它显示一些错误!
import boto3
ec2 = boto3.resource('ec2', region_name = 'us-east-2')
instance = ec2.create_instances(
BlockDeviceMappings=[
{
'DeviceName': '/dev/sdh',
'VirtualName': 'ephemeral1',
'Ebs': {
'Encrypted': False,
'Iops': 500,
'VolumeSize': 100,
'VolumeType': 'io1'
},
},
],
ImageId='ami-XXXXXXXXX',
InstanceType='t2.micro',
KeyName='KeyName',
MaxCount=1,
MinCount=1,
IamInstanceProfile={
'Arn': 'arn:aws:iam::000000000000:user/instance',
'Name': 'instance'
},
InstanceInitiatedShutdownBehavior='stop',
PrivateIpAddress='XXX.XX.XX.XX'
)
Run Code Online (Sandbox Code Playgroud)
它显示错误:
raise error_class(parsed_response, operation_name) botocore.exceptions.ClientError:调用 RunInstances 操作时发生错误 (InvalidParameterCombination):参数“iamInstanceProfile.name”不能与“iamInstanceProfile.arn”组合使用
它正在抱怨这一点:
IamInstanceProfile={
'Arn': 'arn:aws:iam::000000000000:user/instance',
'Name': 'instance'
},
Run Code Online (Sandbox Code Playgroud)
这意味着您不能同时 Arn指定和Name。
原因是 ARN 唯一标识资源,因此名称不是必需的。但是,我承认文档没有说明这一点。
因此,只需删除该Name条目即可。