Search in sources :

Example 6 with AmazonAutoScaling

use of com.amazonaws.services.autoscaling.AmazonAutoScaling in project eureka by Netflix.

the class AwsAsgUtil method retrieveAutoScalingGroupCrossAccount.

private AutoScalingGroup retrieveAutoScalingGroupCrossAccount(String asgAccount, String asgName) {
    logger.debug("Getting cross account ASG for asgName: {}, asgAccount: {}", asgName, asgAccount);
    Credentials credentials = stsCredentials.get(asgAccount);
    if (credentials == null || credentials.getExpiration().getTime() < System.currentTimeMillis() + 1000) {
        stsCredentials.put(asgAccount, initializeStsSession(asgAccount));
        credentials = stsCredentials.get(asgAccount);
    }
    ClientConfiguration clientConfiguration = new ClientConfiguration().withConnectionTimeout(serverConfig.getASGQueryTimeoutMs());
    AmazonAutoScaling autoScalingClient = new AmazonAutoScalingClient(new BasicSessionCredentials(credentials.getAccessKeyId(), credentials.getSecretAccessKey(), credentials.getSessionToken()), clientConfiguration);
    String region = clientConfig.getRegion();
    if (!region.equals("us-east-1")) {
        autoScalingClient.setEndpoint("autoscaling." + region + ".amazonaws.com");
    }
    DescribeAutoScalingGroupsRequest request = new DescribeAutoScalingGroupsRequest().withAutoScalingGroupNames(asgName);
    DescribeAutoScalingGroupsResult result = autoScalingClient.describeAutoScalingGroups(request);
    List<AutoScalingGroup> asgs = result.getAutoScalingGroups();
    if (asgs.isEmpty()) {
        return null;
    } else {
        return asgs.get(0);
    }
}
Also used : DescribeAutoScalingGroupsRequest(com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsRequest) AutoScalingGroup(com.amazonaws.services.autoscaling.model.AutoScalingGroup) AmazonAutoScalingClient(com.amazonaws.services.autoscaling.AmazonAutoScalingClient) BasicSessionCredentials(com.amazonaws.auth.BasicSessionCredentials) AmazonAutoScaling(com.amazonaws.services.autoscaling.AmazonAutoScaling) DescribeAutoScalingGroupsResult(com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsResult) Credentials(com.amazonaws.services.securitytoken.model.Credentials) BasicSessionCredentials(com.amazonaws.auth.BasicSessionCredentials) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) ClientConfiguration(com.amazonaws.ClientConfiguration)

Aggregations

AmazonAutoScaling (com.amazonaws.services.autoscaling.AmazonAutoScaling)6 AutoScalingGroup (com.amazonaws.services.autoscaling.model.AutoScalingGroup)2 DescribeAutoScalingGroupsRequest (com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsRequest)2 ClientConfiguration (com.amazonaws.ClientConfiguration)1 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)1 BasicSessionCredentials (com.amazonaws.auth.BasicSessionCredentials)1 AmazonAutoScalingClient (com.amazonaws.services.autoscaling.AmazonAutoScalingClient)1 CreateAutoScalingGroupRequest (com.amazonaws.services.autoscaling.model.CreateAutoScalingGroupRequest)1 CreateLaunchConfigurationRequest (com.amazonaws.services.autoscaling.model.CreateLaunchConfigurationRequest)1 DeleteAutoScalingGroupRequest (com.amazonaws.services.autoscaling.model.DeleteAutoScalingGroupRequest)1 DeleteLaunchConfigurationRequest (com.amazonaws.services.autoscaling.model.DeleteLaunchConfigurationRequest)1 DescribeAutoScalingGroupsResult (com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsResult)1 Tag (com.amazonaws.services.autoscaling.model.Tag)1 TagDescription (com.amazonaws.services.autoscaling.model.TagDescription)1 Credentials (com.amazonaws.services.securitytoken.model.Credentials)1