Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize Amplify App Deployment with Improved Environment Handling an… #32012

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 12 additions & 23 deletions packages/@aws-cdk/aws-amplify-alpha/test/integ.app-custom-domain.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { App, Stack, StackProps } from 'aws-cdk-lib';
import { Construct } from 'constructs';
import * as acm from 'aws-cdk-lib/aws-certificatemanager';
import * as codecommit from 'aws-cdk-lib/aws-codecommit';
import * as route53 from 'aws-cdk-lib/aws-route53';
import { App, Stack, StackProps } from 'aws-cdk-lib';
import { Construct } from 'constructs';
import * as amplify from '../lib';
import { IntegTest } from '@aws-cdk/integ-tests-alpha';

Expand All @@ -24,8 +24,7 @@ class TestStack extends Stack {
sourceCodeProvider: new amplify.CodeCommitSourceCodeProvider({ repository }),
});

const prodBranch = app.addBranch('main');
const devBranch = app.addBranch('dev');
const [prodBranch, devBranch] = ['main', 'dev'].map(branchName => app.addBranch(branchName));

const hostedZone = route53.PublicHostedZone.fromHostedZoneAttributes(this, 'HostedZone', {
hostedZoneId: props.hostedZoneId,
Expand All @@ -38,34 +37,24 @@ class TestStack extends Stack {
});

const domain = app.addDomain(props.domainName, {
subDomains: [
{
branch: prodBranch,
prefix: 'prod',
},
],
subDomains: [{ branch: prodBranch, prefix: 'prod' }],
customCertificate,
});
domain.mapSubDomain(devBranch);
}
}

/**
* In order to test this you need to have a valid public hosted zone that you can use
* to request certificates for.
*/
const hostedZoneId = process.env.CDK_INTEG_HOSTED_ZONE_ID ?? process.env.HOSTED_ZONE_ID;
if (!hostedZoneId) throw new Error('For this test you must provide your own HostedZoneId as an env var "HOSTED_ZONE_ID". See framework-integ/README.md for details.');
const hostedZoneName = process.env.CDK_INTEG_HOSTED_ZONE_NAME ?? process.env.HOSTED_ZONE_NAME;
if (!hostedZoneName) throw new Error('For this test you must provide your own HostedZoneName as an env var "HOSTED_ZONE_NAME". See framework-integ/README.md for details.');
const domainName = process.env.CDK_INTEG_HOSTED_ZONE_NAME ?? process.env.DOMAIN_NAME;
if (!domainName) throw new Error('For this test you must provide your own DomainName as an env var "DOMAIN_NAME". See framework-integ/README.md for details.');
function getEnvVar(name: string, fallbackName?: string): string {
const value = process.env[name] || (fallbackName ? process.env[fallbackName] : undefined);
if (!value) throw new Error(`Environment variable ${name} is required.`);
return value;
}

const app = new App();
const stack = new TestStack(app, 'cdk-amplify-app-custom-domain', {
hostedZoneId,
hostedZoneName,
domainName,
hostedZoneId: getEnvVar('CDK_INTEG_HOSTED_ZONE_ID', 'HOSTED_ZONE_ID'),
hostedZoneName: getEnvVar('CDK_INTEG_HOSTED_ZONE_NAME', 'HOSTED_ZONE_NAME'),
domainName: getEnvVar('CDK_INTEG_DOMAIN_NAME', 'DOMAIN_NAME'),
});

new IntegTest(app, 'amplify-app-custom-domain-integ', {
Expand Down
Loading