使用EC2创建新的EC2实例时创建标记时出错Java API
我正在尝试使用AWS JAVA API
创建新的EC2 instance
。但是我得到消息,但以下情况除外使用EC2创建新的EC2实例时创建标记时出错Java API
异常线程“main” com.amazonaws.services.ec2.model.AmazonEC2Exception:标签规范 资源类型必须有一个值(服务:AmazonEC2;状态代码: 400; 错误代码:InvalidParameterValue;请求ID:XXXXXX)
public static void main(String[] args) { Ec2Utilities utils = new Ec2Utilities();
Map<String, String> tagMap = new HashMap<String, String>();
tagMap.put("name", "newinstance");
tagMap.put("category", "cat1");
utils.createInstanceFromAmi("t2.micro", "ami-sdfsds", 1, "sg-sdfsd", "nammme", tagMap);
}
public void createInstanceFromAmi(String instanceType, String amiId, int count, String securityGroup,
String keyName, Map<String, String> tagMap) {
AmazonEC2 ec2Client = Auth.getCredentails();
TagSpecification tagSpecs = new TagSpecification();
tagSpecs.setTags(buildTags(tagMap));
RunInstancesRequest runInstancesRequest = new RunInstancesRequest().withTagSpecifications(tagSpecs)
.withInstanceType(instanceType)
.withImageId(amiId)
.withMinCount(count)
.withMaxCount(2)
.withSecurityGroupIds(securityGroup)
.withKeyName(keyName);
RunInstancesResult runInstances = ec2Client.runInstances(runInstancesRequest);
}
private List<Tag> buildTags(Map<String, String> tagMap) {
List<Tag> tagList = new ArrayList<Tag>();
tagMap.forEach((k, v) -> {
tagList.add(new Tag(k, v));
});
System.out.println(tagList);
return tagList;
}
回答:
我固定它自己。我加入这个
List<TagSpecification> tagSpecifications = new ArrayList<>(); tagSpecifications.add(new TagSpecification().withTags(buildTags(tagMap))
凡buildTags(tagMap)
返回`榜”
以上是 使用EC2创建新的EC2实例时创建标记时出错Java API 的全部内容, 来源链接: utcz.com/qa/257115.html