Skip to content

AdminQueries lambda - limit not converted to number #12735

@funes79

Description

@funes79

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 changes to the cloud resources managed by Amplify? Please describe the changes made.

No

Describe the bug

When amplify creates the admin queries a lambda is created to handle the calls.
When calling the listUsers endpoint with limit=20 (for example) the function fails status code 500 is returned.

2023-06-05T15:00:09.904+02:00	INFO Attempting to list users
2023-06-05T15:00:10.343+02:00	INFO SerializationException: STRING_VALUE cannot be converted to Integer at throwDefaultError (/var/runtime/node_modules/@aws-sdk/smithy-client/dist-cjs/default-error-handler.js:8:22) at deserializeAws_json1_1ListUsersCommandError (/var/runtime/node_modules/@aws-sdk/client-cognito-identity-provider/dist-cjs/protocols/Aws_json1_1.js:5075:51) at .... at async /var/task/app.js:170:18 { '$fault': 'client', '$metadata': { httpStatusCode: 400, requestId: 'e0e25dc8-b21d-48f6-bd2a-abd49f9d2f74', extendedRequestId: undefined, cfId: undefined, attempts: 1, totalRetryDelay: 0 }, __type: 'SerializationException' }
2023-06-05T15:00:10.421+02:00	ERROR STRING_VALUE cannot be converted to Integer

The amplify generated (wrong) code of the Lambda (app.js):

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);
  }
});

I hot fixed the code like this:

app.get('/listUsers', async (req, res, next) => {
  try {
    let response;
    let limit = Number(req.query?.limit || 25);
    if (req.query.token) {
      response = await listUsers(limit, req.query.token);
    } else if (req.query.limit) {
      response = await listUsers((Limit = limit));
    } else {
      response = await listUsers();
    }
    res.status(200).json(response);
  } catch (err) {
    next(err);
  }
});

Expected behavior

It should accept the limit parameter and pass it as a number.

Reproduction steps

Add auth, add admin queries.
Run a list users query with limit param.

Project Identifier

No response

Log output

Details
# Put your logs below this line


Additional information

No response

Before submitting, please confirm:

  • I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
  • I have removed any sensitive information from my code snippets and submission.

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-restIssues tied to REST APIsauthIssues tied to the auth category of the CLIbugSomething isn't workingfunctionsIssues tied to the functions categorygood first issueGood for newcomersp2

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions