Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Jun 8, 2020
2 parents daa9318 + 5c3a739 commit 3eb4fcb
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 16 deletions.
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
11 changes: 7 additions & 4 deletions packages/@aws-cdk/aws-ecs/lib/base/base-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,10 +411,13 @@ export abstract class BaseService extends Resource
*
* @example
*
* listener.addTargets(service.loadBalancerTarget({
* containerName: 'MyContainer',
* containerPort: 1234
* }));
* listener.addTargets('ECS', {
* port: 80,
* targets: [service.loadBalancerTarget({
* containerName: 'MyContainer',
* containerPort: 1234,
* })],
* });
*/
public loadBalancerTarget(options: LoadBalancerTargetOptions): IEcsLoadBalancerTarget {
const self = this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@
{
"Ref": "apiDeploymentStageprod896C8101"
},
"/*/{proxy+}"
"/*/*"
]
]
}
Expand Down Expand Up @@ -214,7 +214,7 @@
{
"Ref": "apiC8550315"
},
"/test-invoke-stage/*/{proxy+}"
"/test-invoke-stage/*/*"
]
]
}
Expand Down
4 changes: 2 additions & 2 deletions packages/decdk/test/__snapshots__/synth.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ Object {
Object {
"Ref": "MyApi49610EDF",
},
"/test-invoke-stage/*/{proxy+}",
"/test-invoke-stage/*/*",
],
],
},
Expand Down Expand Up @@ -521,7 +521,7 @@ Object {
Object {
"Ref": "MyApiDeploymentStageprodE1054AF0",
},
"/*/{proxy+}",
"/*/*",
],
],
},
Expand Down

0 comments on commit 3eb4fcb

Please sign in to comment.