amplify-cli: Cannot give postConfirmation trigger access to auth
Describe the bug
I have created a post confirmation trigger using amplify update auth.
I would like to give the postConfirmation trigger access to the user pool in order to get user information and perform other operations that affect the user pool.
I then used amplify update function in order to give the post confirmation function access to the user pool.
However, an error occurs saying: “Error: Cannot add [functionName] due to a cyclic dependency” where [functionName] is the name of my function.
The postConfirmation cloudformation template file is updated with the appropriate permissions but the user pool id is not passed down as a parameter from nested-cloudformation-stack.yml
Desktop (please complete the following information):
- OS: windows 10
Additional context
Invoking amplify update auth and then adding add-to-group functionality works fine but invoking amplify update function and then giving permissions to auth throws the error stated above.
I have tried this with @aws-amplify/cli 3.0.0 and 3.2.0, both result in the same error.
Thanks a lot!
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 7
- Comments: 28 (13 by maintainers)
I was having this same issue and @danielblignaut’s solution here worked wonders. As a matter of fact, it was simpler than that because I only needed to edit
backend-config.jsonand create the CloudFormation template for that resource. TheOutputskey in his figure 2 was already added to my lambda template and theparameters.jsonwasn’t needed because the CLI created them for me automatically innested-cloudformation-stack.yml.I did have to
amplify env checkout {your-env}for the CLI to pick up the changes tobackend-config.json.Hi @royalaid @paulsson ,
not sure if this is the correct approach? But basically my solution involves the following:
Doing the above whilst reading this section of the docs on deploying custom resources made sense to me: https://aws-amplify.github.io/docs/cli-toolchain/quickstart#custom-cloudformation-stacks
figure 1:
figure 2:
figure 3: backend-config.json
cognitoLambdaTriggerPeromissions/postConfirmationPermissions/template.json
cognitoLambdaTriggerPeromissions/postConfirmationPermissions/parameters.json
Running into this issue as well, but with S3 and Lambda. The workflow looks like this:
Output:
The use case here is resizing an image and writing back to S3
cc @kaustavghosh06
I had the same issue. I ended up editing the auth’s cloudformation template, rather than the function’s.
Look for the comment
# Updating lambda role with permissions to Cognito. There will be a policy document section with permissions granted for group creation and adding users to groups. Add the additional policies that you want to the list.Ideally the cli would allow us to select which permissions to grant when setting up a trigger instead of assuming these defaults
I am also running into this issue and it appears my postConfirmation lambda is just using the default value provided for my UserPoolId output because that function never receives the output from the User Pool.
@attilah Thanks for the reply!
I’m currently using a manual workaround for this.
Using
amplify update functionto add auth permissions to cognito triggers will result in a cyclic dependency error message. However, the correct IAM policy is added to the function’s cloud formation template. The cognito user pool id is NOT passed down as a parameter so to fix this, I manually modify the IAM policy to include the user pool id in the iam resource arn@thedgbrt A quick and easy fix is just to manually add the user pool id into the iam policy. Not ideal but gets you unstuck quickly.
@attilah Out of curiosity, how come adding add-to-group functionality to a post confirmation trigger does not register as a cyclic dependency where as adding auth permissions via
amplify update functiondoes cause a cyclic dependency?