class EncryptedImageCopyService {

    public Map<String, String> createEncryptedImages(AuthenticatedContext ac, CloudStack cloudStack, PersistenceNotifier resourceNotifier) {
        String selectedAMIName = cloudStack.getImage().getImageName();
        AwsCredentialView awsCredentialView = new AwsCredentialView(ac.getCloudCredential());
        String regionName = ac.getCloudContext().getLocation().getRegion().value();
        AmazonEC2Client client = awsClient.createAccess(awsCredentialView, regionName);

        Map<String, EncryptedImageConfig> configByGroupName = getEncryptedImageConfigByGroup(cloudStack, selectedAMIName, ac, client, resourceNotifier);

        Map<String, String> imageIdByGroupName = configByGroupName.entrySet()
                .stream()
                .collect(Collectors.toMap(Entry::getKey, e -> e.getValue().getImageId()));
        if (!imageIdByGroupName.isEmpty()) {
            Collection<String> imageIds = new HashSet<>(imageIdByGroupName.values());
            LOGGER.debug("Start polling the availability of the created encrypted AMIs: '{}'", String.join(",", imageIds));
            Waiter<DescribeImagesRequest> imageWaiter = client.waiters().imageAvailable();
            DescribeImagesRequest describeImagesRequest = new DescribeImagesRequest().withImageIds(imageIds);
            StackCancellationCheck stackCancellationCheck = new StackCancellationCheck(ac.getCloudContext().getId());
            run(imageWaiter, describeImagesRequest, stackCancellationCheck, "Encrypted image creation failed");
            LOGGER.info("All created encrypted AMIs are available: '{}'", String.join(",", imageIds));
        }
        return imageIdByGroupName;
    }

}