Skip to content
This repository was archived by the owner on Jul 16, 2024. It is now read-only.

Commit 7a130b9

Browse files
authored
fix: add S3 repository to CdkDeployer (#543)
* add S3 repository to CdkDeployer
1 parent 091761a commit 7a130b9

File tree

9 files changed

+994
-736
lines changed

9 files changed

+994
-736
lines changed

core/.eslintrc.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/.gitattributes

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/.projen/deps.json

Lines changed: 12 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/.projen/tasks.json

Lines changed: 1 addition & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/API.md

Lines changed: 28 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/package.json

Lines changed: 11 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/src/common/cdk-deployer.ts

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { Code, Function, Runtime } from 'aws-cdk-lib/aws-lambda';
1111
import { Rule } from 'aws-cdk-lib/aws-events';
1212
import { LambdaFunction } from 'aws-cdk-lib/aws-events-targets';
1313
import { Utils } from '../utils';
14-
import { Bucket } from 'aws-cdk-lib/aws-s3';
14+
import { Bucket, Location } from 'aws-cdk-lib/aws-s3';
1515
import { startBuild, reportBuild } from './cdk-deployer-build';
1616

1717

@@ -38,25 +38,32 @@ export interface CdkDeployerProps extends cdk.StackProps {
3838
readonly cdkParameters?: { [name: string]: cdk.CfnParameterProps };
3939

4040
/**
41-
* The github repository containing the CDK application
41+
* The github repository containing the CDK application.
42+
* Either `githubRepository` or `s3Repository` needs to be set if `deploymentType` is `CLICK_TO_DEPLOY`.
43+
* @default - Github is not used as the source of the CDK code.
4244
*/
4345
readonly githubRepository?: string;
4446
/**
45-
* The location of the CDK application in the Github repository.
47+
* The branch to use on the Github repository.
48+
* @default - The main branch of the repository
49+
*/
50+
readonly gitBranch?: string;
51+
/**
52+
* The Amazon S3 repository location containing the CDK application. The object key is a Zip file.
53+
* Either `githubRepository` or `s3Repository` needs to be set if `deploymentType` is `CLICK_TO_DEPLOY`.
54+
* @default - S3 is not used as the source of the CDK code
55+
*/
56+
readonly s3Repository?: Location;
57+
/**
58+
* The location of the CDK application in the repository.
4659
* It is used to `cd` into the folder before deploying the CDK application
4760
* @default - The root of the repository
4861
*/
4962
readonly cdkAppLocation?: string;
50-
/**
51-
* The branch to use on the Github repository.
52-
* @default - The main branch of the repository
53-
*/
54-
readonly gitBranch?: string;
55-
5663
/**
5764
* The deployment type
5865
* WORKSHOP_STUDIO: the CDK application is deployed through a workshop studio deployment process
59-
* CLICK_TO_DEPLOY: the CDK application is deployed through a click on a github README button
66+
* CLICK_TO_DEPLOY: the CDK application is deployed through a one-click deploy button
6067
*/
6168
readonly deploymentType: DeploymentType;
6269

@@ -72,19 +79,19 @@ export interface CdkDeployerProps extends cdk.StackProps {
7279
}
7380

7481
/**
75-
* A custom CDK Stack that can be synthetized as a CloudFormation Stack to deploy a CDK application hosted on GitHub.
82+
* A custom CDK Stack that can be synthetized as a CloudFormation Stack to deploy a CDK application hosted on GitHub or on S3 as a Zip file.
7683
* This stack is self contained and can be one-click deployed to any AWS account.
7784
* It can be used for AWS workshop or AWS blog examples deployment when CDK is not supported/desired.
7885
* The stack supports passing the CDK application stack name to deploy (in case there are multiple stacks in the CDK app) and CDK parameters.
7986
*
8087
* It contains the necessary resources to synchronously deploy a CDK application from a GitHub repository:
8188
* * A CodeBuild project to effectively deploy the CDK application
82-
* * A StartBuild custom resource to synchronously trigger the build using a callback pattern based on Event Bridge
83-
* * The necessary roles
89+
* * A StartBuild custom resource to synchronously triggers the build using a callback pattern based on Event Bridge
90+
* * The necessary roles and permissions
8491
*
8592
* The StartBuild CFN custom resource is using the callback pattern to wait for the build completion:
8693
* 1. a Lambda function starts the build but doesn't return any value to the CFN callback URL. Instead, the callback URL is passed to the build project.
87-
* 2. the completion of the build trigger an Event and a second Lambda function which checks the result of the build and send information to the CFN callback URL
94+
* 2. the completion of the build triggers an Event and a second Lambda function which checks the result of the build and send information to the CFN callback URL
8895
*
8996
* * Usage example:
9097
* ```typescript
@@ -117,10 +124,6 @@ export class CdkDeployer extends cdk.Stack {
117124
* @param {CdkDeployerProps} props the CdkDeployer [properties]{@link CdkDeployerProps}
118125
*/
119126
constructor(scope: Construct, props: CdkDeployerProps) {
120-
121-
if((props.deploymentType == DeploymentType.CLICK_TO_DEPLOY) && !props.githubRepository) {
122-
throw new Error('githubRepository is required for CLICK_TO_DEPLOY');
123-
}
124127

125128
super(scope, 'CDKDeployer', {
126129
// Change the Stack Synthetizer to remove the CFN parameters for the CDK version
@@ -279,12 +282,25 @@ export class CdkDeployer extends cdk.Stack {
279282
path: `${cdkAppSourceCodeBucketPrefix.valueAsString}cdk_app.zip`,
280283
});
281284
} else {
282-
source = Source.gitHub({
283-
owner: props.githubRepository!.split('/')[0],
284-
repo: props.githubRepository!.split('/')[1],
285-
branchOrRef: props.gitBranch ? props.gitBranch : undefined,
286-
reportBuildStatus: true,
287-
});
285+
if (props.githubRepository) {
286+
source = Source.gitHub({
287+
owner: props.githubRepository!.split('/')[0],
288+
repo: props.githubRepository!.split('/')[1],
289+
branchOrRef: props.gitBranch ? props.gitBranch : undefined,
290+
reportBuildStatus: true,
291+
});
292+
} else if (props.s3Repository){
293+
source = Source.s3({
294+
bucket: Bucket.fromBucketName(
295+
this,
296+
'CdkAppBucket',
297+
props.s3Repository.bucketName,
298+
),
299+
path: props.s3Repository.objectKey,
300+
});
301+
} else {
302+
throw new Error('githubRepository or s3Repository is required for CLICK_TO_DEPLOY deployment type');
303+
}
288304
}
289305

290306

core/test/e2e/cdk-deployer.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99

1010
import * as cdk from 'aws-cdk-lib';
11-
import { deployStack } from './utils';
11+
import { deployStack, destroyStack } from './utils';
1212

1313
import { CdkDeployer, DeploymentType } from '../../src/common/cdk-deployer';
1414

@@ -20,10 +20,11 @@ const cdkDeployerStack = new CdkDeployer(integTestApp, {
2020
deploymentType: DeploymentType.CLICK_TO_DEPLOY,
2121
githubRepository: 'aws-samples/aws-analytics-reference-architecture',
2222
cdkAppLocation: 'refarch/aws-native',
23+
stackName: 'ara',
2324
gitBranch: 'main',
2425
cdkParameters: {
2526
QuickSightUsername: {
26-
default: 'gromav/gromav-Isengard',
27+
default: '<MY_USER>',
2728
type: 'String',
2829
},
2930
QuickSightIdentityRegion: {

0 commit comments

Comments
 (0)