Derek Kershner
01/03/2022, 4:46 PMlambda.Function.fromFunctionAttributes(
this,
"EventsPublisherFunction",
{
functionArn: ssm.StringParameter.valueForStringParameter(
this,
RESONANCE_EVENTS_PUBLISHER_FUNCTION_ARN_SSM_PARAM
),
role: iam.Role.fromRoleArn(
this,
"EventsPublisherFunctionRole",
ssm.StringParameter.valueForStringParameter(
this,
RESONANCE_EVENTS_PUBLISHER_FUNCTION_ROLE_ARN_SSM_PARAM
)
),
}
);
A sample grant:
distributionDynamoDlq.grantSendMessages(this.eventsPublisherFunction);
this.distributionDynamoTable.grantStreamRead(
this.eventsPublisherFunction
);
The issue is that only the LAST stack deployed sticks, as in it overwrites the other stacks permissions, and only grants eventsPublisherFunction
its resources. Is this expected behavior?thdxr
01/03/2022, 4:48 PMDerek Kershner
01/03/2022, 4:59 PMDerek Kershner
01/03/2022, 5:01 PMthdxr
01/03/2022, 5:12 PMDerek Kershner
01/03/2022, 5:14 PMthdxr
01/03/2022, 5:15 PMDerek Kershner
01/03/2022, 5:15 PMthdxr
01/03/2022, 5:16 PMfromXXX
functions when I have resources created outside of CDK that I need to deal withDerek Kershner
01/03/2022, 5:18 PMDerek Kershner
01/03/2022, 5:20 PMDerek Kershner
01/03/2022, 5:21 PMDerek Kershner
01/03/2022, 5:43 PMprops
or if via fromFunctionAttributes
.Derek Kershner
01/03/2022, 5:45 PMDerek Kershner
01/03/2022, 5:59 PMfromFunctionAttributes
.Derek Kershner
01/03/2022, 6:20 PMI think you're fundamentally breaking one of the tenants of CF and role management, tbh. Each one of your 4 stacks is told 'I get to control permissions' because you import the role and then assign permissions to it. None of the 4 stacks understands that the other 3 exist, and therefore they overwrite the previous changes, because it was told "I get to control this role", but that's not really what you are trying to do. You are trying to have each stack control part of the role. And that's not going to be easy with CFN and the CDK.
So, you could centralize this and keep everything pretty 'stock' in your CDK and CFN. Or, you can write some custom code (behind a CustomResource) that would add to the policy, rather than replace.
Derek Kershner
01/03/2022, 6:21 PMthdxr
01/03/2022, 6:23 PMDerek Kershner
01/03/2022, 6:26 PMgrant
!== add
Derek Kershner
01/03/2022, 6:27 PMDerek Kershner
01/03/2022, 6:33 PMDerek Kershner
01/03/2022, 6:34 PMDerek Kershner
01/03/2022, 6:39 PMFrank
EventsPublisherFunctionRolePolicy531F5E73
, and the last deployed stack overrides itFrank
${id}
is stack id
iam.Role.fromRoleArn(
this,
`${id}-EventsPublisherFunctionRole`,
...
)
Frank
Derek Kershner
01/04/2022, 3:39 PM