Skip to content

Commit a4797b4

Browse files
authored
chore(release): 1.42.1 (#8302)
See CHANGELOG.md ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
2 parents 3b64241 + 6a6324d commit a4797b4

5 files changed

Lines changed: 54 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
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.
44

5+
## [1.42.1](https://github.com/aws/aws-cdk/compare/v1.42.0...v1.42.1) (2020-06-01)
6+
7+
8+
### Bug Fixes
9+
10+
* **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)
11+
512
## [1.42.0](https://github.com/aws/aws-cdk/compare/v1.41.0...v1.42.0) (2020-05-27)
613

714

lerna.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010
"tools/*"
1111
],
1212
"rejectCycles": "true",
13-
"version": "1.42.0"
13+
"version": "1.42.1"
1414
}

packages/@aws-cdk/aws-lambda/lib/function-base.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ export abstract class FunctionBase extends Resource implements IFunction {
284284
action: 'lambda:InvokeFunction',
285285
});
286286

287-
return { statementAdded: true, policyDependable: this.node.findChild(identifier) } as iam.AddToResourcePolicyResult;
287+
return { statementAdded: true, policyDependable: this._functionNode().findChild(identifier) } as iam.AddToResourcePolicyResult;
288288
},
289289
node: this.node,
290290
},
@@ -318,6 +318,15 @@ export abstract class FunctionBase extends Resource implements IFunction {
318318
});
319319
}
320320

321+
/**
322+
* Returns the construct tree node that corresponds to the lambda function.
323+
* For use internally for constructs, when the tree is set up in non-standard ways. Ex: SingletonFunction.
324+
* @internal
325+
*/
326+
protected _functionNode(): ConstructNode {
327+
return this.node;
328+
}
329+
321330
private parsePermissionPrincipal(principal?: iam.IPrincipal) {
322331
if (!principal) {
323332
return undefined;

packages/@aws-cdk/aws-lambda/lib/singleton-lambda.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,14 @@ export class SingletonFunction extends FunctionBase {
8181
down.node.addDependency(this.lambdaFunction);
8282
}
8383

84+
/**
85+
* Returns the construct tree node that corresponds to the lambda function.
86+
* @internal
87+
*/
88+
protected _functionNode(): cdk.ConstructNode {
89+
return this.lambdaFunction.node;
90+
}
91+
8492
private ensureLambda(props: SingletonFunctionProps): IFunction {
8593
const constructName = (props.lambdaPurpose || 'SingletonLambda') + slugify(props.uuid);
8694
const existing = cdk.Stack.of(this).node.tryFindChild(constructName);

packages/@aws-cdk/aws-lambda/test/test.singleton-lambda.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,32 @@ export = {
113113

114114
test.done();
115115
},
116+
117+
'grantInvoke works correctly'(test: Test) {
118+
// GIVEN
119+
const stack = new cdk.Stack();
120+
const singleton = new lambda.SingletonFunction(stack, 'Singleton', {
121+
uuid: '84c0de93-353f-4217-9b0b-45b6c993251a',
122+
code: new lambda.InlineCode('def hello(): pass'),
123+
runtime: lambda.Runtime.PYTHON_2_7,
124+
handler: 'index.hello',
125+
});
126+
127+
// WHEN
128+
const invokeResult = singleton.grantInvoke(new iam.ServicePrincipal('events.amazonaws.com'));
129+
const statement = stack.resolve(invokeResult.resourceStatement);
130+
131+
// THEN
132+
expect(stack).to(haveResource('AWS::Lambda::Permission', {
133+
Action: 'lambda:InvokeFunction',
134+
Principal: 'events.amazonaws.com',
135+
}));
136+
test.deepEqual(statement.action, [ 'lambda:InvokeFunction' ]);
137+
test.deepEqual(statement.principal, { Service: [ 'events.amazonaws.com' ] });
138+
test.deepEqual(statement.effect, 'Allow');
139+
test.deepEqual(statement.resource, [{
140+
'Fn::GetAtt': [ 'SingletonLambda84c0de93353f42179b0b45b6c993251a840BCC38', 'Arn' ],
141+
}]);
142+
test.done();
143+
},
116144
};

0 commit comments

Comments
 (0)