Skip to content

Commit

Permalink
chore(release): 1.42.1 (aws#8302)
Browse files Browse the repository at this point in the history
See CHANGELOG.md

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
mergify[bot] authored Jun 1, 2020
2 parents 3b64241 + 6a6324d commit a4797b4
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 2 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## [1.42.1](https://github.com/aws/aws-cdk/compare/v1.42.0...v1.42.1) (2020-06-01)


### Bug Fixes

* **lambda:** `SingletonFunction.grantInvoke()` API fails with error 'No child with id' ([#8296](https://github.com/aws/aws-cdk/issues/8296)) ([b4e264c](https://github.com/aws/aws-cdk/commit/b4e264c024bc58053412be1343bed6458628f7cb)), closes [#8240](https://github.com/aws/aws-cdk/issues/8240)

## [1.42.0](https://github.com/aws/aws-cdk/compare/v1.41.0...v1.42.0) (2020-05-27)


Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
"tools/*"
],
"rejectCycles": "true",
"version": "1.42.0"
"version": "1.42.1"
}
11 changes: 10 additions & 1 deletion packages/@aws-cdk/aws-lambda/lib/function-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ export abstract class FunctionBase extends Resource implements IFunction {
action: 'lambda:InvokeFunction',
});

return { statementAdded: true, policyDependable: this.node.findChild(identifier) } as iam.AddToResourcePolicyResult;
return { statementAdded: true, policyDependable: this._functionNode().findChild(identifier) } as iam.AddToResourcePolicyResult;
},
node: this.node,
},
Expand Down Expand Up @@ -318,6 +318,15 @@ export abstract class FunctionBase extends Resource implements IFunction {
});
}

/**
* Returns the construct tree node that corresponds to the lambda function.
* For use internally for constructs, when the tree is set up in non-standard ways. Ex: SingletonFunction.
* @internal
*/
protected _functionNode(): ConstructNode {
return this.node;
}

private parsePermissionPrincipal(principal?: iam.IPrincipal) {
if (!principal) {
return undefined;
Expand Down
8 changes: 8 additions & 0 deletions packages/@aws-cdk/aws-lambda/lib/singleton-lambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ export class SingletonFunction extends FunctionBase {
down.node.addDependency(this.lambdaFunction);
}

/**
* Returns the construct tree node that corresponds to the lambda function.
* @internal
*/
protected _functionNode(): cdk.ConstructNode {
return this.lambdaFunction.node;
}

private ensureLambda(props: SingletonFunctionProps): IFunction {
const constructName = (props.lambdaPurpose || 'SingletonLambda') + slugify(props.uuid);
const existing = cdk.Stack.of(this).node.tryFindChild(constructName);
Expand Down
28 changes: 28 additions & 0 deletions packages/@aws-cdk/aws-lambda/test/test.singleton-lambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,32 @@ export = {

test.done();
},

'grantInvoke works correctly'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
const singleton = new lambda.SingletonFunction(stack, 'Singleton', {
uuid: '84c0de93-353f-4217-9b0b-45b6c993251a',
code: new lambda.InlineCode('def hello(): pass'),
runtime: lambda.Runtime.PYTHON_2_7,
handler: 'index.hello',
});

// WHEN
const invokeResult = singleton.grantInvoke(new iam.ServicePrincipal('events.amazonaws.com'));
const statement = stack.resolve(invokeResult.resourceStatement);

// THEN
expect(stack).to(haveResource('AWS::Lambda::Permission', {
Action: 'lambda:InvokeFunction',
Principal: 'events.amazonaws.com',
}));
test.deepEqual(statement.action, [ 'lambda:InvokeFunction' ]);
test.deepEqual(statement.principal, { Service: [ 'events.amazonaws.com' ] });
test.deepEqual(statement.effect, 'Allow');
test.deepEqual(statement.resource, [{
'Fn::GetAtt': [ 'SingletonLambda84c0de93353f42179b0b45b6c993251a840BCC38', 'Arn' ],
}]);
test.done();
},
};

0 comments on commit a4797b4

Please sign in to comment.