@Override
    protected SamlIdPMetadataDocument finalizeMetadataDocument(final SamlIdPMetadataDocument doc,
                                                               final Optional<SamlRegisteredService> registeredService) throws Throwable {
        val bucketNameToUse = AmazonS3SamlIdPMetadataUtils.determineBucketNameFor(registeredService, this.bucketName, s3Client);
        if (s3Client.listBuckets(ListBucketsRequest.builder().build())
            .buckets().stream().noneMatch(b -> b.name().equalsIgnoreCase(bucketNameToUse))) {
            LOGGER.trace("Bucket [{}] does not exist. Creating...", bucketNameToUse);
            val bucket = s3Client.createBucket(CreateBucketRequest.builder().bucket(bucketNameToUse).build());
            LOGGER.debug("Created bucket [{}]", bucket.location());
        }
        return AmazonS3SamlIdPMetadataUtils.putSamlIdPMetadataIntoBucket(s3Client, doc, bucketNameToUse);
    }
This is {@link AmazonS3SamlIdPMetadataGenerator}.

@author Misagh Moayyed
@since 6.0.0
support/cas-server-support-saml-idp-metadata-aws-s3/src/main/java/org/apereo/cas/support/saml/idp/metadata/AmazonS3SamlIdPMetadataGenerator.java