Appsync multi-auth on @function mutation disables iam rule
Describe the bug I have a custom Appsync resolver function that has to be both accessible by a logged-in user that is part of the Admin group, while at the same time by a Lambda function. I have created a custom Mutation resolver for my Appsync:
type Mutation {
updatePaymentStatus(input: String): Response @function(name: "transactResolver-${env}") @auth (rules: [{ allow: private, provider: iam }, { allow: groups, groups: ["Admin"]}])
}
type Response @aws_iam @aws_cognito_user_pools {
code: Int
message: String
body: String
}
Everything works when I just have the single @auth (rules: [{ allow: private, provider: iam }]) rule, but when I add the additional groups auth rule the Lambda function is denied access to the Appsync call, GraphQL error: Not Authorized to access updatePaymentStatus on type Mutation at new ApolloError
Not sure if the two authentications cannot simply share the same @function or I am missing a step, As I assumed that this logic would be the same as when @auth directive is used on @model.
Amplify CLI Version 4.16.1
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
You may want to check the Actions granted to your lambda's role in the CloudFormation template. No idea if this is related, but I discovered a bug(?) in the CLI leading to my lambda being unauthorized to access AppSync, and was able to find a workaround: https://github.com/aws-amplify/amplify-cli/issues/4306
Any update on this issue? I just ran into it as well. The generated request mapping template seems to only check for the group membership.
I was able to reproduce this and it looks like it the generated userPools resolver code is running even when using IAM auth.
Opened a PR for this fix #5014. A workaround for this would be override the resolver and add the authMode check in the resolver code (example below)
## [Start] Determine request authentication mode **
#if( $util.isNullOrEmpty($authMode) && !$util.isNull($ctx.identity) && !$util.isNull($ctx.identity.sub) && !$util.isNull($ctx.identity.issuer) && !$util.isNull($ctx.identity.username) && !$util.isNull($ctx.identity.claims) && !$util.isNull($ctx.identity.sourceIp) && !$util.isNull($ctx.identity.defaultAuthStrategy) )
#set( $authMode = "userPools" )
#end
## [End] Determine request authentication mode **
#if( $authMode == "userPools" )
.....<ADD_GENERATED_AUTH_CODE_HERE>
#end
.....<REST_OF_RESOLVER>
Closing this issue as the fix for this is included in the latest release.
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 *-help channels for those types of questions.