-
Notifications
You must be signed in to change notification settings - Fork 820
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
Wrong Lambda Execution Role #4889
Comments
Any recommendation? This is very frustrating. |
@djsmedes @yuth @attilah hi guys! Sorry to bother you and for being too insistent, but I saw that you've been working on similar issues. It has been days and I still can't sort this out. Could you please give me some inputs to be able to continue working with Amplify? I'm ready to provide further details if needed. Thank you very much! |
The place I'd start is in the chunk of code that does this or similar (this code copy+pasted from the GraphQL from NodeJS you mentioned): const signer = new AWS.Signers.V4(req, "appsync", true);
signer.addAuthorization(AWS.config.credentials, AWS.util.date.getDate()); Is that code executing? After that, does the Incidentally, are you following those docs closely and creating an entirely new request object, or are you reusing the request that comes in as a subkey somewhere in the object from the lambda's |
@djsmedes thank you very much for your answer. While logging some data to CloudWatch to verify what you asked, I realized something else, quite interesting: The unauthorized error I was getting, specifically for The problem was that here: type Query {
adminListUsersData(filter: ModelUserDataFilterInput, limit: Int, nextToken: String): ModelUserDataConnection
@auth(rules: [{allow: groups, groups: ["admins"]}])
@function(name: "userDataResolvers-${env}")
} I used type ModelUserDataConnection {
items: [UserData],
nextToken: String,
scannedCount: Int,
count: Int
} It references To solve the problem I just created a new normal type for the query output without any kind of directive. |
This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs. Looking for a help forum? We recommend joining the Amplify Community Discord server |
Describe the bug
Hi!
I have a Function with full CRUD access configured to my Auth and API (GraphQL) resources.
My API has Cognito User Pools set as primary/default authentication method and IAM as an additional authentication method.
My API has a UserData model defined as follows:
And my Function is implemented as follows:
The problem is that when an admin user calls the
adminListUsersData
query, the AWS SDK inside the function acquires the calling user credentials and not the Lambda execution role credentials. So, when I try interact with my UserData model internally from the Lambda function it is as if the admin user was calling it directly instead of the function.I've followed GraphQL from NodeJS guide to call the API from the Lambda function.
I've also tried to call
AWS.config.update()
method or to useAWS.EnvironmentCredentials()
orAWS.Credentials()
classes to generate new credentials forSigners.V4
withAWS_ACCESS_KEY_ID
,AWS_SECRET_ACCESS_KEY
andAWS_SESSION_TOKEN
from Lambda Runtime Environment Variables, but I still get unauthorized error.I can't get my Lambda function to sign the API request using its own IAM credentials instead of the calling user ones. Please help!
Amplify CLI Version
4.24.2
To Reproduce
See bug description.
Expected behavior
I would expect the Lambda function to use its own execution role to authenticate with the AWS SDK or at least to allow me to choose which identity I would like to use.
Screenshots
None.
Desktop (please complete the following information):
Additional context
None.
The text was updated successfully, but these errors were encountered: