我已经设置了 AmazonAutoScalingAsync 客户端以及许多其他客户端,但我无法检索现有的 ASG。
BasicSessionCredentials sessionCredentials = new BasicSessionCredentials( credentials.getAccessKeyId(), credentials.getSecretAccessKey(), credentials.getSessionToken());
// Assume role
AWSSecurityTokenService sts_client_mfa =
AWSSecurityTokenServiceClientBuilder.standard()
.withRegion(region)
.withCredentials(new AWSStaticCredentialsProvider(sessionCredentials))
.build();
AssumeRoleRequest request =
new AssumeRoleRequest()
.withRoleSessionName("proserv-" + username)
.withRoleArn("myarn");
AssumeRoleResult response = sts_client_mfa.assumeRole(request);
然后我按如下方式构建自动缩放客户端:
autoScalingClient = AmazonAutoScalingAsyncClientBuilder.standard() .withCredentials( new AWSStaticCredentialsProvider( new BasicSessionCredentials( response.getCredentials().getAccessKeyId(), response.getCredentials().getSecretAccessKey(), response.getCredentials().getSessionToken()))) .withRegion(region) .build();
这些与我从 AWS 控制台执行的步骤相同,但在 Java 代码上看不到相同的结果。
getAutoScalingClient()
.describeAutoScalingGroupsAsync()
.get()
.getAutoScalingGroups()
.forEach(
group -> {
System.out.println(group);
});
getAutoScalingClient()
.describeAutoScalingInstancesAsync()
.get()
.getAutoScalingInstances()
.forEach(
entry -> {
System.out.println(entry);
});
有什么想法吗?