diff --git a/.doc_gen/metadata/cloudfront_metadata.yaml b/.doc_gen/metadata/cloudfront_metadata.yaml index 463ee7cc9b9..7f9cff19aaf 100644 --- a/.doc_gen/metadata/cloudfront_metadata.yaml +++ b/.doc_gen/metadata/cloudfront_metadata.yaml @@ -80,6 +80,56 @@ cloudfront_CreateDistribution: - cloudfront.java2.createdistribution.main services: cloudfront: {CreateDistribution} +cloudfront_CreateSaasResources: + title: Create SaaS manager resources &AWS; SDK + title_abbrev: Create a multi-tenant distribution and distribution tenant + synopsis: create a multi-tenant distribution and distribution tenant with various configurations. + category: Scenarios + languages: + Java: + versions: + - sdk_version: 2 + github: javav2/example_code/cloudfront + sdkguide: + excerpts: + - description: >- + The following example demonstrates how to create a multi-tenant distribution with parameters and wildcard certificate. + snippet_tags: + - cloudfront.java2.createmultitenantdistribution.import + - cloudfront.java2.createmultitenantdistribution.main + - description: >- + The following example demonstrates how to create a distribution tenant associated with that template, including utilizing the parameter we declared above. Note that we don't need to add certificate info here because our domain is already covered by the parent template. + snippet_tags: + - cloudfront.java2.createdistributiontenant.import + - cloudfront.java2.createdistributiontenant.title + - cloudfront.java2.createdistributiontenant.nocert + - cloudfront.java2.createdistributiontenant.closebrace + - description: >- + If the viewer certificate was omitted from the parent template, you would need to add certificate info on the tenant(s) associated with it instead. + The following example demonstrates how to do so via an ACM certificate arn that covers the necessary domain for the tenant. + snippet_tags: + - cloudfront.java2.createdistributiontenant.import + - cloudfront.java2.createdistributiontenant.title + - cloudfront.java2.createdistributiontenant.withcert + - cloudfront.java2.createdistributiontenant.closebrace + - description: >- + The following example demonstrates how to do so with a CloudFront-hosted managed certificate request. This is ideal if you don't already have traffic towards your domain. + In this case, we create a ConnectionGroup to generate a RoutingEndpoint. Then we use that RoutingEndpoint to create DNS records which verify domain ownership and point to CloudFront. CloudFront will then automatically serve a token to validate domain ownership and create a managed certificate. + snippet_tags: + - cloudfront.java2.createdistributiontenant.import + - cloudfront.java2.createdistributiontenant.title + - cloudfront.java2.createdistributiontenant.cfhosted + - cloudfront.java2.createdistributiontenant.closebrace + - description: >- + The following example demonstrates how to do so with a self-hosted managed certificate request. This is ideal if you have traffic towards your domain and can't tolerate downtime during a migration. + At the end of this example, the Tenant will be created in a state awaiting domain validation and DNS setup. Follow steps [here](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/managed-cloudfront-certificates.html#complete-domain-ownership) to complete setup when you are ready to migrate traffic. + snippet_tags: + - cloudfront.java2.createdistributiontenant.import + - cloudfront.java2.createdistributiontenant.title + - cloudfront.java2.createdistributiontenant.selfhosted + - cloudfront.java2.createdistributiontenant.closebrace + services: + cloudfront: {CreateDistribution, CreateDistributionTenant} cloudfront_CreateKeyGroup: languages: Java: diff --git a/javav2/example_code/cloudfront/README.md b/javav2/example_code/cloudfront/README.md index 17f6b53ce1b..3b4e22bf802 100644 --- a/javav2/example_code/cloudfront/README.md +++ b/javav2/example_code/cloudfront/README.md @@ -45,6 +45,7 @@ Code excerpts that show you how to call individual service functions. Code examples that show you how to accomplish a specific task by calling multiple functions within the same service. +- [Create a multi-tenant distribution and distribution tenant](src/main/java/com/example/cloudfront/CreateMultiTenantDistribution.java) - [Delete signing resources](src/main/java/com/example/cloudfront/DeleteSigningResources.java) - [Sign URLs and cookies](src/main/java/com/example/cloudfront/CreateCannedPolicyRequest.java) @@ -62,6 +63,18 @@ functions within the same service. +#### Create a multi-tenant distribution and distribution tenant + +This example shows you how to create a multi-tenant distribution and distribution tenant with various configurations. + + + + + + + + + #### Delete signing resources This example shows you how to delete resources that are used to gain access to restricted content in an Amazon Simple Storage Service (Amazon S3) bucket. @@ -112,4 +125,4 @@ in the `javav2` folder. Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. -SPDX-License-Identifier: Apache-2.0 \ No newline at end of file +SPDX-License-Identifier: Apache-2.0 diff --git a/javav2/example_code/cloudfront/pom.xml b/javav2/example_code/cloudfront/pom.xml index 8e4cc9a1e79..c7dffa1155e 100644 --- a/javav2/example_code/cloudfront/pom.xml +++ b/javav2/example_code/cloudfront/pom.xml @@ -26,7 +26,7 @@ org.apache.maven.plugins maven-surefire-plugin - 3.5.2 + 3.5.3 @@ -35,7 +35,7 @@ software.amazon.awssdk bom - 2.31.8 + 2.31.78 pom import @@ -67,6 +67,10 @@ software.amazon.awssdk s3control + + software.amazon.awssdk + route53 + software.amazon.awssdk iam diff --git a/javav2/example_code/cloudfront/src/main/java/com/example/cloudfront/CreateDistributionTenant.java b/javav2/example_code/cloudfront/src/main/java/com/example/cloudfront/CreateDistributionTenant.java new file mode 100644 index 00000000000..90dde11193e --- /dev/null +++ b/javav2/example_code/cloudfront/src/main/java/com/example/cloudfront/CreateDistributionTenant.java @@ -0,0 +1,182 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 + +package com.example.cloudfront; + +// snippet-start:[cloudfront.java2.createdistributiontenant.import] + +import software.amazon.awssdk.services.cloudfront.CloudFrontClient; +import software.amazon.awssdk.services.cloudfront.model.CreateConnectionGroupResponse; +import software.amazon.awssdk.services.cloudfront.model.CreateDistributionTenantResponse; +import software.amazon.awssdk.services.cloudfront.model.DistributionTenant; +import software.amazon.awssdk.services.cloudfront.model.GetConnectionGroupResponse; +import software.amazon.awssdk.services.cloudfront.model.ValidationTokenHost; +import software.amazon.awssdk.services.route53.Route53Client; +import software.amazon.awssdk.services.route53.model.RRType; + +import java.time.Instant; +// snippet-end:[cloudfront.java2.createdistributiontenant.import] + +// snippet-start:[cloudfront.java2.createdistributiontenant.title] +public class CreateDistributionTenant { +// snippet-end:[cloudfront.java2.createdistributiontenant.title] +// snippet-start:[cloudfront.java2.createdistributiontenant.nocert] + public static DistributionTenant createDistributionTenantNoCert(CloudFrontClient cloudFrontClient, + Route53Client route53Client, + String distributionId, + String domain, + String hostedZoneId) { + CreateDistributionTenantResponse createResponse = cloudFrontClient.createDistributionTenant(builder -> builder + .distributionId(distributionId) + .domains(b1 -> b1 + .domain(domain)) + .parameters(b2 -> b2 + .name("tenantName") + .value("myTenant")) + .enabled(false) + .name("no-cert-tenant") + ); + + final DistributionTenant distributionTenant = createResponse.distributionTenant(); + + // Then update the Route53 hosted zone to point your domain at the distribution tenant + // We fetch the RoutingEndpoint to point to via the default connection group that was created for your tenant + final GetConnectionGroupResponse fetchedConnectionGroup = cloudFrontClient.getConnectionGroup(builder -> builder + .identifier(distributionTenant.connectionGroupId())); + + route53Client.changeResourceRecordSets(builder -> builder + .hostedZoneId(hostedZoneId) + .changeBatch(b1 -> b1 + .comment("ChangeBatch comment") + .changes(b2 -> b2 + .resourceRecordSet(b3 -> b3 + .name(domain) + .type("CNAME") + .ttl(300L) + .resourceRecords(b4 -> b4 + .value(fetchedConnectionGroup.connectionGroup().routingEndpoint()))) + .action("CREATE")) + )); + return distributionTenant; + } +// snippet-end:[cloudfront.java2.createdistributiontenant.nocert] + +// snippet-start:[cloudfront.java2.createdistributiontenant.withcert] + public static DistributionTenant createDistributionTenantWithCert(CloudFrontClient cloudFrontClient, + Route53Client route53Client, + String distributionId, + String domain, + String hostedZoneId, + String certificateArn) { + CreateDistributionTenantResponse createResponse = cloudFrontClient.createDistributionTenant(builder -> builder + .distributionId(distributionId) + .domains(b1 -> b1 + .domain(domain)) + .enabled(false) + .name("tenant-with-cert") + .parameters(b2 -> b2 + .name("tenantName") + .value("myTenant")) + .customizations(b3 -> b3 + .certificate(b4 -> b4 + .arn(certificateArn))) // NOTE: Cert must be in Us-East-1 and cover the domain provided in this request + + ); + + final DistributionTenant distributionTenant = createResponse.distributionTenant(); + + // Then update the Route53 hosted zone to point your domain at the distribution tenant + // We fetch the RoutingEndpoint to point to via the default connection group that was created for your tenant + final GetConnectionGroupResponse fetchedConnectionGroup = cloudFrontClient.getConnectionGroup(builder -> builder + .identifier(distributionTenant.connectionGroupId())); + + route53Client.changeResourceRecordSets(builder -> builder + .hostedZoneId(hostedZoneId) + .changeBatch(b1 -> b1 + .comment("ChangeBatch comment") + .changes(b2 -> b2 + .resourceRecordSet(b3 -> b3 + .name(domain) + .type("CNAME") + .ttl(300L) + .resourceRecords(b4 -> b4 + .value(fetchedConnectionGroup.connectionGroup().routingEndpoint()))) + .action("CREATE")) + )); + return distributionTenant; + } +// snippet-end:[cloudfront.java2.createdistributiontenant.withcert] + +// snippet-start:[cloudfront.java2.createdistributiontenant.cfhosted] + public static DistributionTenant createDistributionTenantCfHosted(CloudFrontClient cloudFrontClient, + Route53Client route53Client, + String distributionId, + String domain, + String hostedZoneId) throws InterruptedException { + CreateConnectionGroupResponse createConnectionGroupResponse = cloudFrontClient.createConnectionGroup(builder -> builder + .ipv6Enabled(true) + .name("cf-hosted-connection-group") + .enabled(true)); + + route53Client.changeResourceRecordSets(builder -> builder + .hostedZoneId(hostedZoneId) + .changeBatch(b1 -> b1 + .comment("cf-hosted domain validation record") + .changes(b2 -> b2 + .resourceRecordSet(b3 -> b3 + .name(domain) + .type(RRType.CNAME) + .ttl(300L) + .resourceRecords(b4 -> b4 + .value(createConnectionGroupResponse.connectionGroup().routingEndpoint()))) + .action("CREATE")) + )); + + // Give the R53 record time to propagate, if it isn't being returned by servers yet, the following call will fail + Thread.sleep(60000); + + CreateDistributionTenantResponse createResponse = cloudFrontClient.createDistributionTenant(builder -> builder + .distributionId(distributionId) + .domains(b1 -> b1 + .domain(domain)) + .connectionGroupId(createConnectionGroupResponse.connectionGroup().id()) + .enabled(false) + .name("cf-hosted-tenant") + .parameters(b2 -> b2 + .name("tenantName") + .value("myTenant")) + .managedCertificateRequest(b3 -> b3 + .validationTokenHost(ValidationTokenHost.CLOUDFRONT) + ) + ); + + return createResponse.distributionTenant(); + } +// snippet-end:[cloudfront.java2.createdistributiontenant.cfhosted] + +// snippet-start:[cloudfront.java2.createdistributiontenant.selfhosted] + public static DistributionTenant createDistributionTenantSelfHosted(CloudFrontClient cloudFrontClient, + String distributionId, + String domain) { + CreateDistributionTenantResponse createResponse = cloudFrontClient.createDistributionTenant(builder -> builder + .distributionId(distributionId) + .domains(b1 -> b1 + .domain(domain)) + .parameters(b2 -> b2 + .name("tenantName") + .value("myTenant")) + .enabled(false) + .name("self-hosted-tenant") + .managedCertificateRequest(b3 -> b3 + .validationTokenHost(ValidationTokenHost.SELF_HOSTED) + .primaryDomainName(domain) + ) + ); + + return createResponse.distributionTenant(); + } +// snippet-end:[cloudfront.java2.createdistributiontenant.selfhosted] + +// snippet-start:[cloudfront.java2.createdistributiontenant.closebrace] +} +// snippet-end:[cloudfront.java2.createdistributiontenant.closebrace] \ No newline at end of file diff --git a/javav2/example_code/cloudfront/src/main/java/com/example/cloudfront/CreateMultiTenantDistribution.java b/javav2/example_code/cloudfront/src/main/java/com/example/cloudfront/CreateMultiTenantDistribution.java new file mode 100644 index 00000000000..3a0508c4f07 --- /dev/null +++ b/javav2/example_code/cloudfront/src/main/java/com/example/cloudfront/CreateMultiTenantDistribution.java @@ -0,0 +1,136 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 + +package com.example.cloudfront; + +// snippet-start:[cloudfront.java2.createmultitenantdistribution.import] + +import software.amazon.awssdk.core.internal.waiters.ResponseOrException; +import software.amazon.awssdk.services.cloudfront.CloudFrontClient; +import software.amazon.awssdk.services.cloudfront.model.ConnectionMode; +import software.amazon.awssdk.services.cloudfront.model.CreateDistributionResponse; +import software.amazon.awssdk.services.cloudfront.model.Distribution; +import software.amazon.awssdk.services.cloudfront.model.GetDistributionResponse; +import software.amazon.awssdk.services.cloudfront.model.HttpVersion; +import software.amazon.awssdk.services.cloudfront.model.Method; +import software.amazon.awssdk.services.cloudfront.model.SSLSupportMethod; +import software.amazon.awssdk.services.cloudfront.model.ViewerProtocolPolicy; +import software.amazon.awssdk.services.cloudfront.waiters.CloudFrontWaiter; +import software.amazon.awssdk.services.s3.S3Client; + +import java.time.Instant; +// snippet-end:[cloudfront.java2.createmultitenantdistribution.import] + +// snippet-start:[cloudfront.java2.createmultitenantdistribution.main] +public class CreateMultiTenantDistribution { + public static Distribution CreateMultiTenantDistributionWithCert(CloudFrontClient cloudFrontClient, + S3Client s3Client, + final String bucketName, + final String certificateArn) { + // fetch the origin info if necessary + final String region = s3Client.headBucket(b -> b.bucket(bucketName)).sdkHttpResponse().headers() + .get("x-amz-bucket-region").get(0); + final String originDomain = bucketName + ".s3." + region + ".amazonaws.com"; + String originId = originDomain; // Use the originDomain value for the originId. + + CreateDistributionResponse createDistResponse = cloudFrontClient.createDistribution(builder -> builder + .distributionConfig(b1 -> b1 + .httpVersion(HttpVersion.HTTP2) + .enabled(true) + .comment("Template Distribution with cert built with java") + .connectionMode(ConnectionMode.TENANT_ONLY) + .callerReference(Instant.now().toString()) + .viewerCertificate(certBuilder -> certBuilder + .acmCertificateArn(certificateArn) + .sslSupportMethod(SSLSupportMethod.SNI_ONLY)) + .origins(b2 -> b2 + .quantity(1) + .items(b3 -> b3 + .domainName(originDomain) + .id(originId) + .originPath("/{{tenantName}}") + .s3OriginConfig(builder4 -> builder4 + .originAccessIdentity( + "")))) + .tenantConfig(b5 -> b5 + .parameterDefinitions(b6 -> b6 + .name("tenantName") + .definition(b7 -> b7 + .stringSchema(b8 -> b8 + .comment("tenantName value") + .defaultValue("root") + .required(false))))) + .defaultCacheBehavior(b2 -> b2 + .viewerProtocolPolicy(ViewerProtocolPolicy.ALLOW_ALL) + .targetOriginId(originId) + .cachePolicyId("658327ea-f89d-4fab-a63d-7e88639e58f6") // CachingOptimized Policy + .allowedMethods(b4 -> b4 + .quantity(2) + .items(Method.HEAD, Method.GET))) + )); + + final Distribution distribution = createDistResponse.distribution(); + try (CloudFrontWaiter cfWaiter = CloudFrontWaiter.builder().client(cloudFrontClient).build()) { + ResponseOrException responseOrException = cfWaiter + .waitUntilDistributionDeployed(builder -> builder.id(distribution.id())) + .matched(); + responseOrException.response() + .orElseThrow(() -> new RuntimeException("Distribution not created")); + } + return distribution; + } + + public static Distribution CreateMultiTenantDistributionNoCert(CloudFrontClient cloudFrontClient, + S3Client s3Client, + final String bucketName) { + // fetch the origin info if necessary + final String region = s3Client.headBucket(b -> b.bucket(bucketName)).sdkHttpResponse().headers() + .get("x-amz-bucket-region").get(0); + final String originDomain = bucketName + ".s3." + region + ".amazonaws.com"; + String originId = originDomain; // Use the originDomain value for the originId. + + CreateDistributionResponse createDistResponse = cloudFrontClient.createDistribution(builder -> builder + .distributionConfig(b1 -> b1 + .httpVersion(HttpVersion.HTTP2) + .enabled(true) + .comment("Template Distribution with cert built with java") + .connectionMode(ConnectionMode.TENANT_ONLY) + .callerReference(Instant.now().toString()) + .origins(b2 -> b2 + .quantity(1) + .items(b3 -> b3 + .domainName(originDomain) + .id(originId) + .originPath("/{{tenantName}}") + .s3OriginConfig(builder4 -> builder4 + .originAccessIdentity( + "")))) + .tenantConfig(b5 -> b5 + .parameterDefinitions(b6 -> b6 + .name("tenantName") + .definition(b7 -> b7 + .stringSchema(b8 -> b8 + .comment("tenantName value") + .defaultValue("root") + .required(false))))) + .defaultCacheBehavior(b2 -> b2 + .viewerProtocolPolicy(ViewerProtocolPolicy.ALLOW_ALL) + .targetOriginId(originId) + .cachePolicyId("658327ea-f89d-4fab-a63d-7e88639e58f6") // CachingOptimized Policy + .allowedMethods(b4 -> b4 + .quantity(2) + .items(Method.HEAD, Method.GET))) + )); + + final Distribution distribution = createDistResponse.distribution(); + try (CloudFrontWaiter cfWaiter = CloudFrontWaiter.builder().client(cloudFrontClient).build()) { + ResponseOrException responseOrException = cfWaiter + .waitUntilDistributionDeployed(builder -> builder.id(distribution.id())) + .matched(); + responseOrException.response() + .orElseThrow(() -> new RuntimeException("Distribution not created")); + } + return distribution; + } +} +// snippet-end:[cloudfront.java2.createmultitenantdistribution.main] \ No newline at end of file diff --git a/javav2/example_code/cloudfront/src/main/java/com/example/cloudfront/DeleteDistributionTenant.java b/javav2/example_code/cloudfront/src/main/java/com/example/cloudfront/DeleteDistributionTenant.java new file mode 100644 index 00000000000..9f89fe706f2 --- /dev/null +++ b/javav2/example_code/cloudfront/src/main/java/com/example/cloudfront/DeleteDistributionTenant.java @@ -0,0 +1,21 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 + +package com.example.cloudfront; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import software.amazon.awssdk.services.cloudfront.CloudFrontClient; +import software.amazon.awssdk.services.cloudfront.model.DeleteDistributionTenantResponse; +import software.amazon.awssdk.services.cloudfront.model.GetDistributionTenantResponse; + +public class DeleteDistributionTenant { + public static void deleteDistributionTenant(final CloudFrontClient cloudFrontClient, final String distributionTenantId) { + GetDistributionTenantResponse response = cloudFrontClient.getDistributionTenant(b -> b + .identifier(distributionTenantId)); + String etag = response.eTag(); + DeleteDistributionTenantResponse deleteResponse = cloudFrontClient.deleteDistributionTenant(b -> b + .id(distributionTenantId) + .ifMatch(etag)); + } +} diff --git a/javav2/example_code/cloudfront/src/main/resources/config.properties b/javav2/example_code/cloudfront/src/main/resources/config.properties index 9bab6b4ddff..91981ae1b96 100644 --- a/javav2/example_code/cloudfront/src/main/resources/config.properties +++ b/javav2/example_code/cloudfront/src/main/resources/config.properties @@ -3,4 +3,10 @@ distributionId = # CloudFrontSigningTest properties publicKeyFileName = cf_public_key.pem -privateKeyFullPath = \ No newline at end of file +privateKeyFullPath = + +# SaaSManagerTest properties +wildcardCertificateArn = +s3BucketName = +baseDomain = +hostedZoneId = \ No newline at end of file diff --git a/javav2/example_code/cloudfront/src/test/java/SaaSManagerTest.java b/javav2/example_code/cloudfront/src/test/java/SaaSManagerTest.java new file mode 100644 index 00000000000..748315e21d3 --- /dev/null +++ b/javav2/example_code/cloudfront/src/test/java/SaaSManagerTest.java @@ -0,0 +1,178 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 + +import com.example.cloudfront.CreateMultiTenantDistribution; +import com.example.cloudfront.CreateDistributionTenant; +import com.example.cloudfront.DeleteDistribution; +import com.example.cloudfront.DeleteDistributionTenant; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.MethodOrderer; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestMethodOrder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import software.amazon.awssdk.regions.Region; +import software.amazon.awssdk.services.cloudfront.CloudFrontClient; +import software.amazon.awssdk.services.route53.Route53Client; +import software.amazon.awssdk.services.s3.S3Client; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; + +import static org.junit.jupiter.api.Assertions.assertFalse; + +@TestInstance(TestInstance.Lifecycle.PER_METHOD) +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) +public class SaaSManagerTest { + private static final Logger logger = LoggerFactory.getLogger(SaaSManagerTest.class); + private static CloudFrontClient cloudFrontClient; + private static S3Client s3Client; + private static Route53Client route53Client; + private static Region region; + private static String s3BucketName = ""; + private static String certificateArn = ""; + private static String distributionNoCertId = ""; + private static String distributionWithCertId = ""; + private static String distributionTenantWithCertId = ""; + private static String distributionTenantNoCertId = ""; + private static String distributionTenantSelfHostedId = ""; + private static String distributionTenantCfHostedId = ""; + private static String baseDomain = ""; + private static String hostedZoneId = ""; + + @BeforeAll + public static void setUp() { + + // Run tests on Real AWS resources. + region = Region.AWS_GLOBAL; + cloudFrontClient = CloudFrontClient.builder() + .region(region) + .build(); + s3Client = S3Client.builder() + .region(Region.US_WEST_2) + .build(); + route53Client = Route53Client.builder() + .region(region) + .build(); + + try (InputStream input = SaaSManagerTest.class.getClassLoader().getResourceAsStream("config.properties")) { + + Properties prop = new Properties(); + + if (input == null) { + System.out.println("Sorry, unable to find config.properties"); + return; + } + + // Load a properties file from the classpath, inside static method. + prop.load(input); + + // Populate the data members required for all tests. + certificateArn = prop.getProperty("wildcardCertificateArn"); + s3BucketName = prop.getProperty("s3BucketName"); + baseDomain = prop.getProperty("baseDomain"); + hostedZoneId = prop.getProperty("hostedZoneId"); + + } catch (IOException ex) { + ex.printStackTrace(); + } + } + + @AfterAll + static void tearDownScaffolding() { + tearDownCloudFrontResources(); + } + + static void tearDownCloudFrontResources() { + DeleteDistributionTenant.deleteDistributionTenant(cloudFrontClient, distributionTenantNoCertId); + DeleteDistributionTenant.deleteDistributionTenant(cloudFrontClient, distributionTenantWithCertId); + DeleteDistributionTenant.deleteDistributionTenant(cloudFrontClient, distributionTenantCfHostedId); + DeleteDistributionTenant.deleteDistributionTenant(cloudFrontClient, distributionTenantSelfHostedId); + DeleteDistribution.deleteDistribution(cloudFrontClient, distributionNoCertId); + DeleteDistribution.deleteDistribution(cloudFrontClient, distributionWithCertId); + } + + + @Test + @Order(1) + public void CreateMultiTenantDistributionWithCert() { + distributionWithCertId = CreateMultiTenantDistribution.CreateMultiTenantDistributionWithCert( + cloudFrontClient, + s3Client, + s3BucketName, + certificateArn).id(); + assertFalse(distributionWithCertId.isEmpty()); + logger.info("Test 1 passed"); + } + + @Test + @Order(2) + public void CreateMultiTenantDistributionNoCert() { + distributionNoCertId = CreateMultiTenantDistribution.CreateMultiTenantDistributionNoCert( + cloudFrontClient, + s3Client, + s3BucketName).id(); + assertFalse(distributionNoCertId.isEmpty()); + logger.info("Test 2 passed"); + } + + @Test + @Order(3) + public void CreateDistributionTenantWithCert() { + distributionTenantWithCertId = CreateDistributionTenant.createDistributionTenantWithCert( + cloudFrontClient, + route53Client, + distributionNoCertId, + "my-tenant-cert." + baseDomain, + hostedZoneId, + certificateArn + ).id(); + assertFalse(distributionTenantWithCertId.isEmpty()); + logger.info("Test 3 passed"); + } + + @Test + @Order(4) + public void CreateDistributionTenantNoCert() { + distributionTenantNoCertId = CreateDistributionTenant.createDistributionTenantNoCert( + cloudFrontClient, + route53Client, + distributionWithCertId, + "my-tenant-no-cert." + baseDomain, + hostedZoneId + ).id(); + assertFalse(distributionTenantNoCertId.isEmpty()); + logger.info("Test 4 passed"); + } + + @Test + @Order(5) + public void CreateDistributionTenantCfHosted() throws InterruptedException { + distributionTenantCfHostedId = CreateDistributionTenant.createDistributionTenantCfHosted( + cloudFrontClient, + route53Client, + distributionNoCertId, + "my-tenant-cf-hosted." + baseDomain, + hostedZoneId + ).id(); + assertFalse(distributionTenantCfHostedId.isEmpty()); + logger.info("Test 5 passed"); + } + + @Test + @Order(6) + public void CreateDistributionTenantSelfHosted() { + distributionTenantSelfHostedId = CreateDistributionTenant.createDistributionTenantSelfHosted( + cloudFrontClient, + distributionNoCertId, + "my-tenant-self-hosted." + baseDomain + ).id(); + assertFalse(distributionTenantSelfHostedId.isEmpty()); + logger.info("Test 6 passed"); + } +} +