我正在创建具有特定IAM角色的Amazon EC2实例。
现在,我想分离该IAM角色并附加一个新的IAM角色,或替换为一个新的IAM角色。我正在找到与CLI有关的选项,但是当实例通过Java代码运行时,我找不到任何选项。
这是我的代码:
RunInstancesRequest runInstancesRequest = new RunInstancesRequest().withImageId(imageID)
.withBlockDeviceMappings(blockDeviceMappings).withInstanceType(type).withMinCount(1).withMaxCount(1)
.withIamInstanceProfile(new IamInstanceProfileSpecification().withName(iamRole))
.withUserData(getUserDataScript())
.withNetworkInterfaces(new InstanceNetworkInterfaceSpecification().withAssociatePublicIpAddress(true)
.withDeviceIndex(0).withSubnetId(subnetID).withGroups(groups));
RunInstancesResult runInstancesResult = ec2Client.runInstances(runInstancesRequest);