class AutoScalingGroupHandler {

    public Map<AutoScalingGroup, String> getAutoScalingGroups(AmazonCloudFormationClient cloudFormationClient, AmazonAutoScalingClient autoScalingClient,
            CloudResource cfResource) {
        DescribeStackResourcesRequest resourcesRequest = new DescribeStackResourcesRequest();
        resourcesRequest.setStackName(cfResource.getName());
        DescribeStackResourcesResult resourcesResult = cloudFormationClient.describeStackResources(resourcesRequest);
        Map<String, String> autoScalingGroups = resourcesResult.getStackResources().stream()
                .filter(stackResource -> "AWS::AutoScaling::AutoScalingGroup".equalsIgnoreCase(stackResource.getResourceType()))
                .collect(Collectors.toMap(StackResource::getPhysicalResourceId, StackResource::getLogicalResourceId));
        DescribeAutoScalingGroupsRequest request = new DescribeAutoScalingGroupsRequest();
        request.setAutoScalingGroupNames(autoScalingGroups.keySet());
        List<AutoScalingGroup> scalingGroups = autoScalingClient.describeAutoScalingGroups(request).getAutoScalingGroups();
        return scalingGroups.stream()
                .collect(Collectors.toMap(scalingGroup -> scalingGroup, scalingGroup -> autoScalingGroups.get(scalingGroup.getAutoScalingGroupName())));
    }

}