-
Notifications
You must be signed in to change notification settings - Fork 824
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
amplify update function - auth cyclic dependency issue #13717
Comments
Tagging @josefaidt in case you have any ideas. I saw your comment on a similar issue a little while ago. Thank you! |
@pr0g from the name it appears you are trying to creating a |
Thank you very much for your reply @ykethan. I see, that makes total sense, I'll double check what wasn't working for me then as I'd perhaps wrongly assumed it was the authorization. I'm essentially trying to lookup the Cognito real name from the username to store along with some other data in DynamoDB. I'll have a look today with fresh eyes and report back with an update. Thanks for the pointer 👍 |
Okay I followed up with this and I still can't seem to get it to work. When first adding the trigger, no auth logic is added for being able to access Cognito. If I call some code like...
I get the error message:
If I then do
instead of...
If I look in the Lambda function Environment variables section in the AWS Console, I see I see that I can access the User Pool Id from the event parameter from the docs you shared ( I guess my two workaround options are:
In the Post Authentication CloudFormation template, I don't see any of the permissions listed to access Cognito unless I run
Which is surprising to me, I don't know how the Lambda function would have acccess without that. Sorry if I'm missing something super obvious, but if you could help me understand the context a bit better I'd really appreciate it. Thanks again! |
I tried the refactor approach I described but no luck... When I call:
I get this error:
It's really odd because we do have Is there anything else I can do to debug what's going wrong and why I don't have valid permissions to call Cognito from this Cognito Lambda trigger? |
As a quick workaround I've found adding the below to
It seems something similar to this should be added by default when creating the Cognito Lambda trigger perhaps? |
@pr0g the Lambda function requires additional permission we can add the permissions on the |
Hi @ykethan, thanks for getting back to me and thanks for the doc link, I'll have a read through soon. I just want to check in the So something like this...
The issue I was finding was the environment variable wasn't automatically populated for the Cognito Lambda trigger (this normally happens when adding For example I don't see
|
@pr0g The env variable should be available using |
@ykethan Okay good to know, I just guess there's a subtle difference between a Cognito Lambda trigger function, and a regular Lambda function, in terms of how you grant them permissions to Cognito, which was what tripped me up. It's a little confusing, but glad it's working now. I wound up modifying
I could refine it in future to use the Thank you for your help, we can close this issue now. |
This issue is now closed. Comments on closed issues are hard for our team to see. |
How did you install the Amplify CLI?
npm
If applicable, what version of Node.js are you using?
v16.20.2
Amplify CLI Version
12.11.0
What operating system are you using?
macOS
Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.
No
Describe the bug
I added a Cognito Lambda trigger using
amplify add auth
. I now want to add permissions to that function so it can access Cognito (auth).amplify update function
,Resource access permissions
auth
(api
is already selected and working)Query
andMutation
read
operations (for just getting read access to Cognito)I then get this error:
I have checked
amplify/cli.json
and I have"breakcirculardependency"
set totrue
I've tried to make manual edits to work around the Amplify CLI, but unfortunately hit errors with the CloudFormation stack deploy
Is there a way I can add
auth
access to my new Cognito Lambda trigger function? Any help/workaround would be hugely appreciated!Expected behavior
amplify update function
allows auth to be added without hittingError: Cannot add <app>PostAuthentication due to a cyclic dependency
errorReproduction steps
See above
Project Identifier
--send-report
failedLog output
amplify-cli-2024-04-16.log
Additional information
If there's a way to do this manually as a temporary workaround that would be great to know!
Before submitting, please confirm:
The text was updated successfully, but these errors were encountered: