-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
custom-resources: cannot make custom resource lambda function depend on a managed policy #27782
Comments
You will need to make sure the custom managed policy would attach to the role before the creation of the custom resource. One option as you mentioned above is to create the role with your managed policies const role = new Role(
this,
'Role',
{
assumedBy: new ServicePrincipal('lambda.amazonaws.com'),
managedPolicies: [managedPolicy]
}
); Another option is to make the role depend on the managed policies like role.node.addDependency(managedPolicy) This ensures the managedPolicy to be created first, and then the role and eventually the custom resource which implicitly depends on the role. |
Perhaps this would be better labeled as an enhancement. I'm proposing adding a dependency between the To illustrate this, I have created a fork of https://github.com/toxygene/aws-cdk/tree/toxygene/custom-resources-dependency My changes can be seen in this commit: toxygene@de3209b |
Closing in favor of new feature request: #28049 |
|
Describe the bug
I am trying to create an AwsCustomResource with a VPC and role. The role has a managed policy attached to it, which grants the
ec2
actions necessary to create a Lambda function within a VPC. I have also manually set the managed policy as a dependency of the AwsCustomResource.Expected Behavior
Deploys successfully.
Current Behavior
The deploy fails with the following message:
Reproduction Steps
Possible Solution
Is it possible to make the AwsCustomResource construct a dependency of the Lambda Function it creates, thus preserving user-space constructs with the AwsCustomResource?
Additional Information/Context
It is possible to work around this issue by creating the managed policy, then passing it to the constructor of the role.
This work around isn't obvious, as it took me a while before I realized it.
CDK CLI Version
2.103.1
Framework Version
No response
Node.js Version
v18.18.2
OS
MacOs 13.6
Language
TypeScript
Language Version
No response
Other information
No response
The text was updated successfully, but these errors were encountered: