-
Notifications
You must be signed in to change notification settings - Fork 72
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
Can't grant ListUsers permission to Lambda #1375
Comments
Hey @FBS-Alex, thank you for reaching out. Marking this as feature request to provide ListUsers permissions. but you be add the permissions using the override on the backend
|
Thank you for the reply @ykethan For reference, my backend.ts: import {defineBackend} from '@aws-amplify/backend';
import {auth} from './auth/resource';
import {data} from './data/resource';
import {adminActions} from "./functions/admin-actions/resource";
import {AuthorizationType, CognitoUserPoolsAuthorizer, Cors, LambdaRestApi} from "aws-cdk-lib/aws-apigateway";
import {Duration, Stack} from "aws-cdk-lib";
import {PolicyStatement} from "aws-cdk-lib/aws-iam";
const backend = defineBackend({
auth,
data,
adminActions
});
backend.adminActions.resources.lambda.addToRolePolicy(new PolicyStatement({
actions: ['cognito-idp:ListUsers', 'cognito-idp:ListUsersInGroup'],
resources: [backend.auth.resources.userPool.userPoolArn],
}));
const apiGatewayStack = backend.createStack("apigateway-stack");
const authorizer = new CognitoUserPoolsAuthorizer(apiGatewayStack, 'AdminActionsAuthorizer', {
cognitoUserPools: [backend.auth.resources.userPool]
});
// create a REST API resource
const adminActionsAPI = new LambdaRestApi(apiGatewayStack, "AdminActions", {
handler: backend.adminActions.resources.lambda,
defaultCorsPreflightOptions: {
allowOrigins: Cors.ALL_ORIGINS,
allowMethods: Cors.ALL_METHODS,
allowHeaders: Cors.DEFAULT_HEADERS,
maxAge: Duration.minutes(5),
},
defaultMethodOptions: {
authorizationType: AuthorizationType.COGNITO,
authorizer
}
});
// patch the custom REST API resource to the expected output configuration
backend.addOutput({
custom: {
apiId: adminActionsAPI.restApiId,
apiEndpoint: adminActionsAPI.url,
apiName: adminActionsAPI.restApiName,
apiRegion: Stack.of(apiGatewayStack).region,
},
}); |
@FBS-Alex on quick test, I was able to workaround the issue by using the attachInlinePolicy and creating the policy in the auth stack.
|
@ykethan Thanks a lot, that worked :) |
Closing this issue as this is now supported, documentation providing this: https://docs.amplify.aws/react/build-a-backend/auth/grant-access-to-auth-resources/ |
Environment information
Description
I'm trying to create an AdminQueries Rest API, but I can't grant the ListUsers permission to the Lambda function.
Basically trying to do something like in this example
But since the cognito-idp:ListUsers permission is not mapped to any action it doesn't work. The example uses the manageUsers action but it doesn't contain this permission so the example itself doesn't work either.
The text was updated successfully, but these errors were encountered: