根据业务需求,我们需要通过API调用控制AWS自动伸缩组策略。我已经阅读了Java SDK客户端文档,但是找不到与API调用相关的任何信息。我不确定这是否可行。以下是要求,
应该能够获得特定AWS自动缩放组的所需容量
应该能够获取特定AWS自动缩放组的最小计数
应该能够获得特定AWS自动缩放组的最大计数
通过Java SDK设置自动扩展组所需的容量。
AmazonAutoScaling client = AmazonAutoScalingClientBuilder.standard()
.withCredentials(new ProfileCredentialsProvider(CredentialProfiles.API_MANAGER.getProfile())).build();
SetDesiredCapacityRequest request = new SetDesiredCapacityRequest()
.withAutoScalingGroupName(autoScaleGroupNameValue).withDesiredCapacity(desiredCapacityValue)
.withHonorCooldown(true);
SetDesiredCapacityResult response = get().setDesiredCapacity(request);
请告知我是否可以通过AWS开发工具包Java客户端执行这些操作。
答案 0 :(得分:1)
设置所需容量
AmazonAutoScaling asgClient = AmazonAutoScalingClientBuilder.standard().withCredentials(CREDENTIALS_PROVIDER).build();
SetDesiredCapacityRequest dcRequest = new SetDesiredCapacityRequest()
.withAutoScalingGroupName("AUTO_SCALING_GROUP_NAME").withDesiredCapacity(2);
SetDesiredCapacityResult dcResult = asgClient.setDesiredCapacity(dcRequest);
要检索ASG详细信息
DescribeAutoScalingGroupsRequest asgRequest = new DescribeAutoScalingGroupsRequest()
.withAutoScalingGroupNames("AUTO_SCALING_GROUP_NAME");
DescribeAutoScalingGroupsResult asgResult = asgClient.describeAutoScalingGroups(asgRequest);
List<AutoScalingGroup> groupList = asgResult.getAutoScalingGroups();
groupList.forEach((asgroup) -> System.out.println(asgroup.getDesiredCapacity())); // Desired Capacity
groupList.forEach((asgroup) -> System.out.println(asgroup.getMinSize())); // Min
groupList.forEach((asgroup) -> System.out.println(asgroup.getMaxSize())); // Max