Skip to content

Commit

Permalink
Merge branch 'master' into feature/expose-cluster-security-group
Browse files Browse the repository at this point in the history
  • Loading branch information
Elad Ben-Israel authored Jun 9, 2020
2 parents 810e258 + 480d4c0 commit 6f5bf1d
Show file tree
Hide file tree
Showing 130 changed files with 3,572 additions and 1,364 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ for tracking bugs and feature requests.
* Ask a question on [Stack Overflow](https://stackoverflow.com/questions/tagged/aws-cdk)
and tag it with `aws-cdk`
* Come join the AWS CDK community on [Gitter](https://gitter.im/awslabs/aws-cdk)
* Talk in the CDK channel of the [AWS Developers Slack workspace](https://awsdevelopers.slack.com) (invite required)
* Open a support ticket with [AWS Support](https://console.aws.amazon.com/support/home#/)
* If it turns out that you may have found a bug,
please open an [issue](https://github.com/aws/aws-cdk/issues/new)
Expand Down
8 changes: 8 additions & 0 deletions allowed-breaking-changes.txt
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
# Actually adding any artifact type will break the load() type signature because I could have written
# const x: A | B = Manifest.load();
# and that won't typecheck if Manifest.load() adds a union arm and now returns A | B | C.
change-return-type:@aws-cdk/cloud-assembly-schema.Manifest.load

removed:@aws-cdk/core.BootstraplessSynthesizer.DEFAULT_ASSET_PUBLISHING_ROLE_ARN
removed:@aws-cdk/core.DefaultStackSynthesizer.DEFAULT_ASSET_PUBLISHING_ROLE_ARN
removed:@aws-cdk/core.DefaultStackSynthesizerProps.assetPublishingExternalId
removed:@aws-cdk/core.DefaultStackSynthesizerProps.assetPublishingRoleArn
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,6 @@ echo "==========================================================================
echo "building..."
time lerna run $bail --stream $runtarget || fail

DOWNLOAD_LATEST=true /bin/bash scripts/check-api-compatibility.sh
/bin/bash scripts/check-api-compatibility.sh

touch $BUILD_INDICATOR
8 changes: 6 additions & 2 deletions packages/@aws-cdk/aws-apigateway/lib/method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,15 +236,15 @@ export class Method extends Resource {
}

const stage = this.restApi.deploymentStage.stageName.toString();
return this.restApi.arnForExecuteApi(this.httpMethod, this.resource.path, stage);
return this.restApi.arnForExecuteApi(this.httpMethod, pathForArn(this.resource.path), stage);
}

/**
* Returns an execute-api ARN for this method's "test-invoke-stage" stage.
* This stage is used by the AWS Console UI when testing the method.
*/
public get testMethodArn(): string {
return this.restApi.arnForExecuteApi(this.httpMethod, this.resource.path, 'test-invoke-stage');
return this.restApi.arnForExecuteApi(this.httpMethod, pathForArn(this.resource.path), 'test-invoke-stage');
}

private renderIntegration(integration?: Integration): CfnMethod.IntegrationProperty {
Expand Down Expand Up @@ -380,3 +380,7 @@ export enum AuthorizationType {
*/
COGNITO = 'COGNITO_USER_POOLS',
}

function pathForArn(path: string): string {
return path.replace(/\{[^\}]*\}/g, '*'); // replace path parameters (like '{bookId}') with asterisk
}
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@
{
"Ref": "stage0661E4AC"
},
"/*/{proxy+}"
"/*/*"
]
]
}
Expand Down Expand Up @@ -188,7 +188,7 @@
{
"Ref": "lambdarestapiF559E4F2"
},
"/test-invoke-stage/*/{proxy+}"
"/test-invoke-stage/*/*"
]
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@
{
"Ref": "booksapiDeploymentStageprod55D8E03E"
},
"/GET/books/{book_id}"
"/GET/books/*"
]
]
}
Expand Down Expand Up @@ -687,7 +687,7 @@
{
"Ref": "booksapiE1885304"
},
"/test-invoke-stage/GET/books/{book_id}"
"/test-invoke-stage/GET/books/*"
]
]
}
Expand Down Expand Up @@ -768,7 +768,7 @@
{
"Ref": "booksapiDeploymentStageprod55D8E03E"
},
"/DELETE/books/{book_id}"
"/DELETE/books/*"
]
]
}
Expand Down Expand Up @@ -805,7 +805,7 @@
{
"Ref": "booksapiE1885304"
},
"/test-invoke-stage/DELETE/books/{book_id}"
"/test-invoke-stage/DELETE/books/*"
]
]
}
Expand Down
46 changes: 46 additions & 0 deletions packages/@aws-cdk/aws-apigateway/test/test.method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,52 @@ export = {
test.done();
},

'"methodArn" and "testMethodArn" replace path parameters with asterisks'(test: Test) {
const stack = new cdk.Stack();
const api = new apigw.RestApi(stack, 'test-api');
const petId = api.root.addResource('pets').addResource('{petId}');
const commentId = petId.addResource('comments').addResource('{commentId}');
const method = commentId.addMethod('GET');

test.deepEqual(stack.resolve(method.methodArn), {
'Fn::Join': [
'',
[
'arn:',
{ Ref: 'AWS::Partition' },
':execute-api:',
{ Ref: 'AWS::Region' },
':',
{ Ref: 'AWS::AccountId' },
':',
{ Ref: 'testapiD6451F70' },
'/',
{ Ref: 'testapiDeploymentStageprod5C9E92A4' },
'/GET/pets/*/comments/*',
],
],
});

test.deepEqual(stack.resolve(method.testMethodArn), {
'Fn::Join': [
'',
[
'arn:',
{ Ref: 'AWS::Partition' },
':execute-api:',
{ Ref: 'AWS::Region' },
':',
{ Ref: 'AWS::AccountId' },
':',
{ Ref: 'testapiD6451F70' },
'/test-invoke-stage/GET/pets/*/comments/*',
],
],
});

test.done();
},

'integration "credentialsRole" can be used to assume a role when calling backend'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
Expand Down
22 changes: 22 additions & 0 deletions packages/@aws-cdk/aws-cloud9/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,25 @@ const c9env = new cloud9.Ec2Environment(this, 'Cloud9Env3', {
new cdk.CfnOutput(this, 'URL', { value: c9env.ideUrl });
```

### Cloning Repositories

Use `clonedRepositories` to clone one or multiple AWS Codecommit repositories into the environment:

```ts
// create a codecommit repository to clone into the cloud9 environment
const repoNew = new codecommit.Repository(this, 'RepoNew', {
repositoryName: 'new-repo',
});

// import an existing codecommit repository to clone into the cloud9 environment
const repoExisting = codecommit.Repository.fromRepositoryName(stack, 'RepoExisting', 'existing-repo');

// create a new Cloud9 environment and clone the two repositories
new cloud9.Ec2Environment(stack, 'C9Env', {
vpc,
clonedRepositories: [
cloud9.CloneRepository.fromCodeCommit(repoNew, '/src/new-repo'),
cloud9.CloneRepository.fromCodeCommit(repoExisting, '/src/existing-repo'),
],
});
```
38 changes: 35 additions & 3 deletions packages/@aws-cdk/aws-cloud9/lib/environment.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as codecommit from '@aws-cdk/aws-codecommit';
import * as ec2 from '@aws-cdk/aws-ec2';
import * as cdk from '@aws-cdk/core';
import { CfnEnvironmentEC2 } from '../lib/cloud9.generated';
Expand All @@ -20,7 +21,6 @@ export interface IEc2Environment extends cdk.IResource {
* @attribute environmentE2Arn
*/
readonly ec2EnvironmentArn: string;

}

/**
Expand Down Expand Up @@ -61,6 +61,14 @@ export interface Ec2EnvironmentProps {
* @default - no description
*/
readonly description?: string;

/**
* The AWS CodeCommit repository to be cloned
*
* @default - do not clone any repository
*/
// readonly clonedRepositories?: Cloud9Repository[];
readonly clonedRepositories?: CloneRepository[];
}

/**
Expand Down Expand Up @@ -125,11 +133,35 @@ export class Ec2Environment extends cdk.Resource implements IEc2Environment {
name: props.ec2EnvironmentName,
description: props.description,
instanceType: props.instanceType?.toString() ?? ec2.InstanceType.of(ec2.InstanceClass.BURSTABLE2, ec2.InstanceSize.MICRO).toString(),
subnetId: this.vpc.selectSubnets(vpcSubnets).subnetIds[0] ,
subnetId: this.vpc.selectSubnets(vpcSubnets).subnetIds[0],
repositories: props.clonedRepositories ? props.clonedRepositories.map(r => ({
repositoryUrl: r.repositoryUrl,
pathComponent: r.pathComponent,
})) : undefined,
});
this.environmentId = c9env.ref;
this.ec2EnvironmentArn = c9env.getAtt('Arn').toString();
this.ec2EnvironmentName = c9env.getAtt('Name').toString();
this.ideUrl = `https://${this.stack.region}.console.aws.amazon.com/cloud9/ide/${this.environmentId}`;
}
}
}

/**
* The class for different repository providers
*/
export class CloneRepository {
/**
* import repository to cloud9 environment from AWS CodeCommit
*
* @param repository the codecommit repository to clone from
* @param path the target path in cloud9 environment
*/
public static fromCodeCommit(repository: codecommit.IRepository, path: string): CloneRepository {
return {
repositoryUrl: repository.repositoryCloneUrlHttp,
pathComponent: path,
};
}

private constructor(public readonly repositoryUrl: string, public readonly pathComponent: string) {}
}
7 changes: 6 additions & 1 deletion packages/@aws-cdk/aws-cloud9/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,22 @@
"license": "Apache-2.0",
"devDependencies": {
"@aws-cdk/assert": "0.0.0",
"@aws-cdk/aws-codecommit": "0.0.0",
"cdk-build-tools": "0.0.0",
"cdk-integ-tools": "0.0.0",
"cfn2ts": "0.0.0",
"pkglint": "0.0.0"
},
"dependencies": {
"@aws-cdk/core": "0.0.0",
"@aws-cdk/aws-codecommit": "0.0.0",
"@aws-cdk/aws-ec2": "0.0.0",
"constructs": "^3.0.2"
},
"homepage": "https://github.com/aws/aws-cdk",
"peerDependencies": {
"@aws-cdk/core": "0.0.0",
"@aws-cdk/aws-codecommit": "0.0.0",
"@aws-cdk/aws-ec2": "0.0.0",
"constructs": "^3.0.2"
},
Expand All @@ -87,7 +90,9 @@
"exclude": [
"resource-attribute:@aws-cdk/aws-cloud9.Ec2Environment.environmentEc2Arn",
"resource-attribute:@aws-cdk/aws-cloud9.Ec2Environment.environmentEc2Name",
"props-physical-name:@aws-cdk/aws-cloud9.Ec2EnvironmentProps"
"props-physical-name:@aws-cdk/aws-cloud9.Ec2EnvironmentProps",
"docs-public-apis:@aws-cdk/aws-cloud9.CloneRepository.pathComponent",
"docs-public-apis:@aws-cdk/aws-cloud9.CloneRepository.repositoryUrl"
]
},
"stability": "experimental",
Expand Down
42 changes: 40 additions & 2 deletions packages/@aws-cdk/aws-cloud9/test/cloud9.environment.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { expect as expectCDK, haveResource } from '@aws-cdk/assert';
import { expect as expectCDK, haveResource, haveResourceLike } from '@aws-cdk/assert';
import * as codecommit from '@aws-cdk/aws-codecommit';
import * as ec2 from '@aws-cdk/aws-ec2';
import * as cdk from '@aws-cdk/core';
import * as cloud9 from '../lib';
Expand Down Expand Up @@ -66,4 +67,41 @@ test('throw error when subnetSelection not specified and the provided VPC has no
instanceType: ec2.InstanceType.of(ec2.InstanceClass.C5, ec2.InstanceSize.LARGE),
});
}).toThrow(/no subnetSelection specified and no public subnet found in the vpc, please specify subnetSelection/);
});
});

test('can use CodeCommit repositories', () => {
// WHEN
const repo = codecommit.Repository.fromRepositoryName(stack, 'Repo', 'foo');

new cloud9.Ec2Environment(stack, 'C9Env', {
vpc,
clonedRepositories: [
cloud9.CloneRepository.fromCodeCommit(repo, '/src'),
],
});
// THEN
expectCDK(stack).to(haveResourceLike('AWS::Cloud9::EnvironmentEC2', {
InstanceType: 't2.micro',
Repositories: [
{
PathComponent: '/src',
RepositoryUrl: {
'Fn::Join': [
'',
[
'https://git-codecommit.',
{
Ref: 'AWS::Region',
},
'.',
{
Ref: 'AWS::URLSuffix',
},
'/v1/repos/foo',
],
],
},
},
],
}));
});
17 changes: 17 additions & 0 deletions packages/@aws-cdk/aws-cloud9/test/integ.cloud9.expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -323,10 +323,27 @@
}
}
},
"Repo02AC86CF": {
"Type": "AWS::CodeCommit::Repository",
"Properties": {
"RepositoryName": "foo"
}
},
"C9EnvF05FC3BE": {
"Type": "AWS::Cloud9::EnvironmentEC2",
"Properties": {
"InstanceType": "t2.micro",
"Repositories": [
{
"PathComponent": "/foo",
"RepositoryUrl": {
"Fn::GetAtt": [
"Repo02AC86CF",
"CloneUrlHttp"
]
}
}
],
"SubnetId": {
"Ref": "VPCPublicSubnet1SubnetB4246D30"
}
Expand Down
16 changes: 14 additions & 2 deletions packages/@aws-cdk/aws-cloud9/test/integ.cloud9.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as codecommit from '@aws-cdk/aws-codecommit';
import * as ec2 from '@aws-cdk/aws-ec2';
import * as cdk from '@aws-cdk/core';
import * as cloud9 from '../lib';
Expand All @@ -11,13 +12,24 @@ export class Cloud9Env extends cdk.Stack {
natGateways: 1,
});

// create a codecommit repository to clone into the cloud9 environment
const repo = new codecommit.Repository(this, 'Repo', {
repositoryName: 'foo',
});

// create a cloud9 ec2 environment in a new VPC
const c9env = new cloud9.Ec2Environment(this, 'C9Env', { vpc });
const c9env = new cloud9.Ec2Environment(this, 'C9Env', {
vpc,
// clone repositories into the environment
clonedRepositories: [
cloud9.CloneRepository.fromCodeCommit(repo, '/foo'),
],
});
new cdk.CfnOutput(this, 'URL', { value: c9env.ideUrl });
new cdk.CfnOutput(this, 'ARN', { value: c9env.ec2EnvironmentArn });
}
}

const app = new cdk.App();

new Cloud9Env(app, 'C9Stack');
new Cloud9Env(app, 'C9Stack');
Loading

0 comments on commit 6f5bf1d

Please sign in to comment.