#✅ - admin actions

19 messages · Page 1 of 1 (latest)

green agate
#

admin action API is receiving authorized query for listUsers but is not returning anything. CloudWatch log attached.

thanks in advance

green agate
smoky stag
#

hey could you paste the code for the lambda function and backend setup? i can try and repro the issue

green agate
#

thanks here is lambda code

#

that was cognitoActions.js

#

here is App.js

#

and here is index.js

#

/* eslint-disable /
/

  • Copyright 2019-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  • Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
  • the License. A copy of the License is located at
  • http://aws.amazon.com/apache2.0/
    
  • or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
  • CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
  • and limitations under the License.
    */
    const awsServerlessExpress = require('aws-serverless-express');
    const app = require('./app');

const server = awsServerlessExpress.createServer(app);

exports.handler = (event, context) => {
console.log(EVENT: ${JSON.stringify(event)});
awsServerlessExpress.proxy(server, event, context);
};

#

i didn't change any of these - they were built through amplify update auth

#

gen 1, amplify version 6

#

let me know if you need anything else

smoky stag
#

aaah i see this is Gen 1.
For a quick test could you add some console log on the response and result in the following snippets

app.get('/listUsers', async (req, res, next) => {
  try {
    let response;
    if (req.query.token) {
      response = await listUsers(req.query.limit || 25, req.query.token);
    } else if (req.query.limit) {
      response = await listUsers((Limit = req.query.limit));
    } else {
      response = await listUsers();
    }
    res.status(200).json(response);
  } catch (err) {
    next(err);
  }
});
async function listUsers(Limit, PaginationToken) {
  const params = {
    UserPoolId: userPoolId,
    ...(Limit && { Limit }),
    ...(PaginationToken && { PaginationToken }),
  };

  console.log('Attempting to list users');

  try {
    const result = await cognitoIdentityProviderClient.send(new ListUsersCommand(params));

    // Rename to NextToken for consistency with other Cognito APIs
    result.NextToken = result.PaginationToken;
    delete result.PaginationToken;

    return result;
  } catch (err) {
    console.log(err);
    throw err;
  }
}

additionally, the issue may be related to https://github.com/aws-amplify/amplify-cli/issues/12735
as shown in the sample, could you try casting req.query to a number and let us know if this fixes it

let limit = Number(req.query?.limit || 25);
GitHub

How did you install the Amplify CLI? npm If applicable, what version of Node.js are you using? No response Amplify CLI Version 12 What operating system are you using? Ubuntu Did you make any manual...

green agate
#

will do thanks

green agate
#

add console logs and also updatd App.js with the suggested fix from 12735

#

and it worked!

#

thanks!

warm swallowBOT
#

✅ - admin actions