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

feat(amplify): Add missing Framework and Platform Cfn properties to Amplify #23818

Closed
Show file tree
Hide file tree
Changes from 3 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
8 changes: 8 additions & 0 deletions packages/@aws-cdk/aws-amplify/lib/branch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@ export interface BranchOptions {
* @default false
*/
readonly performanceMode?: boolean;

/**
* The Framework for the branch.
*
* @default - no framework
*/
readonly framework?: string;
}

/**
Expand Down Expand Up @@ -180,6 +187,7 @@ export class Branch extends Resource implements IBranch {
pullRequestEnvironmentName: props.pullRequestEnvironmentName,
stage: props.stage,
enablePerformanceMode: props.performanceMode,
framework: props.framework,
});

this.arn = branch.attrArn;
Expand Down
242 changes: 128 additions & 114 deletions packages/@aws-cdk/aws-amplify/test/branch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,141 +4,155 @@ import { Asset } from '@aws-cdk/aws-s3-assets';
import { SecretValue, Stack } from '@aws-cdk/core';
import * as amplify from '../lib';

let stack: Stack;
let app: amplify.App;
beforeEach(() => {
stack = new Stack();
app = new amplify.App(stack, 'App', {
sourceCodeProvider: new amplify.GitHubSourceCodeProvider({
owner: 'aws',
repository: 'aws-cdk',
oauthToken: SecretValue.unsafePlainText('secret'),
}),
describe('amplify app', () => {
let stack: Stack;
let app: amplify.App;
beforeEach(() => {
stack = new Stack();
app = new amplify.App(stack, 'App', {
sourceCodeProvider: new amplify.GitHubSourceCodeProvider({
owner: 'aws',
repository: 'aws-cdk',
oauthToken: SecretValue.unsafePlainText('secret'),
}),
});
});
});

test('create a branch', () => {
// WHEN
app.addBranch('dev');
test('create a branch', () => {
// WHEN
app.addBranch('dev');

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::Amplify::Branch', {
AppId: {
'Fn::GetAtt': [
'AppF1B96344',
'AppId',
],
},
BranchName: 'dev',
EnableAutoBuild: true,
EnablePullRequestPreview: true,
// THEN
Template.fromStack(stack).hasResourceProperties('AWS::Amplify::Branch', {
AppId: {
'Fn::GetAtt': [
'AppF1B96344',
'AppId',
],
},
BranchName: 'dev',
EnableAutoBuild: true,
EnablePullRequestPreview: true,
});
});
});

test('with basic auth from credentials', () => {
// WHEN
app.addBranch('dev', {
basicAuth: amplify.BasicAuth.fromCredentials('username', SecretValue.unsafePlainText('password')),
});
test('with basic auth from credentials', () => {
// WHEN
app.addBranch('dev', {
basicAuth: amplify.BasicAuth.fromCredentials('username', SecretValue.unsafePlainText('password')),
});

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::Amplify::Branch', {
BasicAuthConfig: {
EnableBasicAuth: true,
Password: 'password',
Username: 'username',
},
// THEN
Template.fromStack(stack).hasResourceProperties('AWS::Amplify::Branch', {
BasicAuthConfig: {
EnableBasicAuth: true,
Password: 'password',
Username: 'username',
},
});
});
});

test('with basic auth from generated password', () => {
// WHEN
app.addBranch('dev', {
basicAuth: amplify.BasicAuth.fromGeneratedPassword('username'),
});
test('with basic auth from generated password', () => {
// WHEN
app.addBranch('dev', {
basicAuth: amplify.BasicAuth.fromGeneratedPassword('username'),
});

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::Amplify::Branch', {
BasicAuthConfig: {
EnableBasicAuth: true,
Password: {
'Fn::Join': [
'',
[
'{{resolve:secretsmanager:',
{
Ref: 'AppdevdevBasicAuthB25D2314',
},
':SecretString:password::}}',
// THEN
Template.fromStack(stack).hasResourceProperties('AWS::Amplify::Branch', {
BasicAuthConfig: {
EnableBasicAuth: true,
Password: {
'Fn::Join': [
'',
[
'{{resolve:secretsmanager:',
{
Ref: 'AppdevdevBasicAuthB25D2314',
},
':SecretString:password::}}',
],
],
],
},
Username: 'username',
},
Username: 'username',
},
});
});
});

test('with env vars', () => {
// WHEN
const branch = app.addBranch('dev', {
environmentVariables: {
key1: 'value1',
},
test('with env vars', () => {
// WHEN
const branch = app.addBranch('dev', {
environmentVariables: {
key1: 'value1',
},
});
branch.addEnvironment('key2', 'value2');

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::Amplify::Branch', {
EnvironmentVariables: [
{
Name: 'key1',
Value: 'value1',
},
{
Name: 'key2',
Value: 'value2',
},
],
});
});
branch.addEnvironment('key2', 'value2');

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::Amplify::Branch', {
EnvironmentVariables: [
{
Name: 'key1',
Value: 'value1',
test('with asset deployment', () => {
// WHEN
const asset = new Asset(app, 'SampleAsset', {
path: path.join(__dirname, './test-asset'),
});
app.addBranch('dev', { asset });

// THEN
Template.fromStack(stack).hasResourceProperties('Custom::AmplifyAssetDeployment', {
ServiceToken: {
'Fn::GetAtt': [
'comamazonawscdkcustomresourcesamplifyassetdeploymentproviderNestedStackcomamazonawscdkcustomresourcesamplifyassetdeploymentproviderNestedStackResource89BDFEB2',
'Outputs.comamazonawscdkcustomresourcesamplifyassetdeploymentprovideramplifyassetdeploymenthandlerproviderframeworkonEventA449D9A9Arn',
],
},
AppId: {
'Fn::GetAtt': [
'AppF1B96344',
'AppId',
],
},
{
Name: 'key2',
Value: 'value2',
BranchName: 'dev',
S3ObjectKey: '8c89eadc6be22019c81ed6b9c7d9929ae10de55679fd8e0e9fd4c00f8edc1cda.zip',
S3BucketName: {
'Fn::Sub': 'cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}',
},
],
});
});
});

test('with asset deployment', () => {
// WHEN
const asset = new Asset(app, 'SampleAsset', {
path: path.join(__dirname, './test-asset'),
});
app.addBranch('dev', { asset });
test('with performance mode', () => {
// WHEN
app.addBranch('dev', {
performanceMode: true,
});

// THEN
Template.fromStack(stack).hasResourceProperties('Custom::AmplifyAssetDeployment', {
ServiceToken: {
'Fn::GetAtt': [
'comamazonawscdkcustomresourcesamplifyassetdeploymentproviderNestedStackcomamazonawscdkcustomresourcesamplifyassetdeploymentproviderNestedStackResource89BDFEB2',
'Outputs.comamazonawscdkcustomresourcesamplifyassetdeploymentprovideramplifyassetdeploymenthandlerproviderframeworkonEventA449D9A9Arn',
],
},
AppId: {
'Fn::GetAtt': [
'AppF1B96344',
'AppId',
],
},
BranchName: 'dev',
S3ObjectKey: '8c89eadc6be22019c81ed6b9c7d9929ae10de55679fd8e0e9fd4c00f8edc1cda.zip',
S3BucketName: {
'Fn::Sub': 'cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}',
},
// THEN
Template.fromStack(stack).hasResourceProperties('AWS::Amplify::Branch', {
EnablePerformanceMode: true,
});
});
});

test('with performance mode', () => {
// WHEN
app.addBranch('dev', {
performanceMode: true,
});
test('with framework', () => {
// WHEN
app.addBranch('dev', {
framework: 'testFramework',
});

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::Amplify::Branch', {
EnablePerformanceMode: true,
// THEN
Template.fromStack(stack).hasResourceProperties('AWS::Amplify::Branch', {
Framework: 'testFramework',
});
});
});
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "21.0.0",
"version": "29.0.0",
"files": {
"673eedce19cf9e5cb7018f3029adb9937d4c7c7b167af1f80c69613cac83b7da": {
"source": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"version":"21.0.0"}
{"version":"29.0.0"}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "21.0.0",
"version": "29.0.0",
"testCases": {
"integ.app-asset-deployment": {
"stacks": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
{
"version": "21.0.0",
"version": "29.0.0",
"artifacts": {
"Tree": {
"type": "cdk:tree",
"properties": {
"file": "tree.json"
}
},
"cdk-amplify-app-asset-deployment.assets": {
"type": "cdk:asset-manifest",
"properties": {
Expand Down Expand Up @@ -62,36 +56,15 @@
"type": "aws:cdk:logicalId",
"data": "CheckBootstrapVersion"
}
],
"AppmainF505BAED": [
{
"type": "aws:cdk:logicalId",
"data": "AppmainF505BAED",
"trace": [
"!!DESTRUCTIVE_CHANGES: WILL_DESTROY"
]
}
],
"AppmainDeploymentResource442DE93D": [
{
"type": "aws:cdk:logicalId",
"data": "AppmainDeploymentResource442DE93D",
"trace": [
"!!DESTRUCTIVE_CHANGES: WILL_DESTROY"
]
}
],
"comamazonawscdkcustomresourcesamplifyassetdeploymentproviderNestedStackcomamazonawscdkcustomresourcesamplifyassetdeploymentproviderNestedStackResource89BDFEB2": [
{
"type": "aws:cdk:logicalId",
"data": "comamazonawscdkcustomresourcesamplifyassetdeploymentproviderNestedStackcomamazonawscdkcustomresourcesamplifyassetdeploymentproviderNestedStackResource89BDFEB2",
"trace": [
"!!DESTRUCTIVE_CHANGES: WILL_DESTROY"
]
}
]
},
"displayName": "cdk-amplify-app-asset-deployment"
},
"Tree": {
"type": "cdk:tree",
"properties": {
"file": "tree.json"
}
}
}
}
Loading