Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,20 @@ export class Provider extends Construct implements ICustomResourceProvider {
};
}

private addPermissions(frameworkLambda: lambda.Function, userDefinedHandlerLambda: lambda.IFunction) {
userDefinedHandlerLambda.grantInvoke(frameworkLambda);

/*
lambda:GetFunction is needed as the framework Lambda use it to poll the state of User Defined
Handler until it is ACTIVE state
*/
frameworkLambda.addToRolePolicy(new iam.PolicyStatement({
effect: iam.Effect.ALLOW,
actions: ['lambda:GetFunction'],
resources: [userDefinedHandlerLambda.functionArn],
}));
}

private createFunction(entrypoint: string, name?: string) {
const fn = new lambda.Function(this, `framework-${entrypoint}`, {
code: lambda.Code.fromAsset(RUNTIME_HANDLER_PATH, {
Expand All @@ -271,11 +285,11 @@ export class Provider extends Construct implements ICustomResourceProvider {
});

fn.addEnvironment(consts.USER_ON_EVENT_FUNCTION_ARN_ENV, this.onEventHandler.functionArn);
this.onEventHandler.grantInvoke(fn);
this.addPermissions(fn, this.onEventHandler);

if (this.isCompleteHandler) {
fn.addEnvironment(consts.USER_IS_COMPLETE_FUNCTION_ARN_ENV, this.isCompleteHandler.functionArn);
this.isCompleteHandler.grantInvoke(fn);
this.addPermissions(fn, this.isCompleteHandler);
}

return fn;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -474,14 +474,58 @@ describe('role', () => {
});

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', {
const template = Template.fromStack(stack);
template.hasResourceProperties('AWS::Lambda::Function', {
Role: {
'Fn::GetAtt': [
'MyRoleF48FFE04',
'Arn',
],
},
});
template.hasResourceProperties('AWS::IAM::Policy', {
PolicyDocument: {
Statement: [
{
Action: 'lambda:InvokeFunction',
Effect: 'Allow',
Resource: [
{
'Fn::GetAtt': [
'MyHandler6B74D312',
'Arn',
],
},
{
'Fn::Join': [
'',
[
{
'Fn::GetAtt': [
'MyHandler6B74D312',
'Arn',
],
},
':*',
],
],
},
],
},
{
Action: 'lambda:GetFunction',
Effect: 'Allow',
Resource: {
'Fn::GetAtt': [
'MyHandler6B74D312',
'Arn',
],
},
},
],
Version: '2012-10-17',
},
});
});

it('uses default role otherwise', () => {
Expand All @@ -498,14 +542,58 @@ describe('role', () => {
});

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', {
const template = Template.fromStack(stack);
template.hasResourceProperties('AWS::Lambda::Function', {
Role: {
'Fn::GetAtt': [
'MyProviderframeworkonEventServiceRole8761E48D',
'Arn',
],
},
});
template.hasResourceProperties('AWS::IAM::Policy', {
PolicyDocument: {
Statement: [
{
Action: 'lambda:InvokeFunction',
Effect: 'Allow',
Resource: [
{
'Fn::GetAtt': [
'MyHandler6B74D312',
'Arn',
],
},
{
'Fn::Join': [
'',
[
{
'Fn::GetAtt': [
'MyHandler6B74D312',
'Arn',
],
},
':*',
],
],
},
],
},
{
Action: 'lambda:GetFunction',
Effect: 'Allow',
Resource: {
'Fn::GetAtt': [
'MyHandler6B74D312',
'Arn',
],
},
},
],
Version: '2012-10-17',
},
});
});
});

Expand Down
Loading