Comments for Test the APIs

There has to be an existing domain associated with this user pool. (Service: AWSCognitoIdentityProviderService; Status Code: 400; Error Code: InvalidParameterException; Request ID: a88495fd-c63c-466f-93d4-87e663173b90)

I’m getting this error in the UI customization part of the user pool (lol that’s how much I went digging for this error).

None of the solutions worked above for the Invalid identity pool configuration. I’ve checked with all the debugging, including the other pages where I referenced the IAM roles policy and the IDP ids. Please, I’ve been stuck on this for a while now!

I’m unable to reach authenticated API calls in my service. I even tried commenting out:

authorizer: aws_iam

And I can access the URL in my browser or with curl, but I still get a 403 from CloudFront. I’ve verified that my policy simulator works. Also, I don’t see these requests showing up in my API gateway logs that I enabled. Here is the output:

Authenticating with User Pool
Getting temporary credentials
Making API request
{
  status: 403,
  statusText: 'Forbidden',
  data: '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">\n' +
    '<HTML><HEAD><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">\n' +
    '<TITLE>ERROR: The request could not be satisfied</TITLE>\n' +
    '</HEAD><BODY>\n' +
    '<H1>403 ERROR</H1>\n' +
    '<H2>The request could not be satisfied.</H2>\n' +
    '<HR noshade size="1px">\n' +
    'Bad request.\n' +
    "We can't connect to the server for this app or website at this time. There might be too much traffic or a configuration error. Try again later, or contact the app or website owner.\n" +
    '<BR clear="all">\n' +
    'If you provide content to customers through CloudFront, you can find steps to troubleshoot and help prevent this error by reviewing the CloudFront documentation.\n' +
    '<BR clear="all">\n' +
    '<HR noshade size="1px">\n' +
    '<PRE>\n' +
    'Generated by cloudfront (CloudFront)\n' +
    'Request ID: SxQCgPWk5BVfPQ9nhGFSG-1jgz6xvvxKPN4bizzw4rTYL-9PJL8mvRj4w==\n' +
    '</PRE>\n' +
    '<ADDRESS>\n' +
    '</ADDRESS>\n' +
    '</BODY></HTML>'
}

I solved this. It’s because I was including a body on a GET request.

apig-test --username='admin@example.com' --password='Passw0rd!' --user-pool-id='*****' --app-client-id='******' --cognito-region='us-east-1' --identity-pool-id='*****' --invoke-url='https://6mizip1zs8.execute-api.us-east-1.amazonaws.com/dev/' --api-gateway-region='us-east-1' --path-template='notes' --methos='POST' --body='{"content":"hello world","attachment":"hellp.jpg"}'

I also tried to remove the slash after dev in invoke-url and add it in path-template but it doesn’t change anything.

I receive the following error.

  status: 403,
  statusText: 'Forbidden',
  data: '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">\n' +
    '<HTML><HEAD><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">\n' +
    '<TITLE>ERROR: The request could not be satisfied</TITLE>\n' +
    '</HEAD><BODY>\n' +
    '<H1>403 ERROR</H1>\n' +
    '<H2>The request could not be satisfied.</H2>\n' +
    '<HR noshade size="1px">\n' +
    'Bad request.\n' +
    "We can't connect to the server for this app or website at this time. There might be too much traffic or a configuration error. Try again later, or contact the app or website owner.\n" +
    '<BR clear="all">\n' +
    'If you provide content to customers through CloudFront, you can find steps to troubleshoot and help prevent this error by reviewing the CloudFront documentation.\n' +
    '<BR clear="all">\n' +
    '<HR noshade size="1px">\n' +
    '<PRE>\n' +
    'Generated by cloudfront (CloudFront)\n' +
    'Request ID: Twl3TjhrKw2DTu9dEo0Rd1xQfILId5w_Mpa-tAa1s55dlo0uJWoMZQ==\n' +
    '</PRE>\n' +
    '<ADDRESS>\n' +
    '</ADDRESS>\n' +
    '</BODY></HTML>'
}```

Thanks for pointing this out!

Since 500 errors are generated by our code, you can add console.log and check the logs. Did you try this?

Oh I had no idea. Do you mind editing the chapter and submitting a PR?

Hmm it looks like you tried creating a part of this before? Can you try creating these resources from the start?

Oh wow. The error message for that is terrible!

1 Like

Can you try removing the trailing slash on the invoke URL? In the chapter we use this as the example:

https://ly55wbovq4.execute-api.us-east-1.amazonaws.com/prod

I tried running the npx aws-api-gateway-cli-test command, but I keep receiving this error message:

{
  status: 500,
  statusText: 'Internal Server Error',
  data: {
    error: 'One or more parameter values were invalid: Type mismatch for key userId expected: S actual: NULL'
  }
}

I put a console.log(e); into the handler-lib.js (like the guide told me to), this is the log:

2020-06-19T11:03:52.229Z	a3e766aa-180b-4813-8d26-0532272d1cb7	INFO	ValidationException: One or more parameter values were invalid: Type mismatch for key userId expected: S actual: NULL
    at Request.extractError (/var/runtime/node_modules/aws-sdk/lib/protocol/json.js:51:27)
    at Request.callListeners (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:106:20)
    at Request.emit (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:78:10)
    at Request.emit (/var/runtime/node_modules/aws-sdk/lib/request.js:683:14)
    at Request.transition (/var/runtime/node_modules/aws-sdk/lib/request.js:22:10)
    at AcceptorStateMachine.runTo (/var/runtime/node_modules/aws-sdk/lib/state_machine.js:14:12)
    at /var/runtime/node_modules/aws-sdk/lib/state_machine.js:26:10
    at Request.<anonymous> (/var/runtime/node_modules/aws-sdk/lib/request.js:38:9)
    at Request.<anonymous> (/var/runtime/node_modules/aws-sdk/lib/request.js:685:12)
    at Request.callListeners (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:116:18) {
  code: 'ValidationException',
  time: 2020-06-19T11:03:52.224Z,
  requestId: 'H7DJVLNSQD316M7PG9N2D5IKI3VV4KQNSO5AEMVJF66Q9ASUAAJG',
  statusCode: 400,
  retryable: false,
  retryDelay: 44.24938233657806
}

I more or less understand what it means, but I can’t figure out where I could’ve made a mistake.

Hello @jayair, I commented here 6 days ago now and I’m at a point where I can’t do anything in the guide anymore if I don’t get the API working correctly (I have to connect the frontend application to it now). I know there’s probably a good reason nobody answered yet, but in case the reason is nobody seeing the message (because I didn’t @ anybody), I want to try and ‘fix’ that now.

This is the post/problem I am talking about:

From the error it sounds like the field names you are using the DynamoDB call are incorrect. Make sure to compare it to the one we have in the sample repo:

@jayair Thanks for the quick answer now! I don’t know why I didn’t try this before, but replacing the event.requestContext.identity.cognitoIdentityId with a string like “test” lead to a successful API call. Also, logging the value of event.requestContext.identity.cognitoIdentityId returns null
. Do you have any idea where this could come from?

import * as uuid from "uuid";
import handler from "./libs/handler-lib";
import dynamoDb from "./libs/dynamodb-lib";

export const main = handler(async (event, context) => {
    const data = JSON.parse(event.body);
    const params = {
        TableName: process.env.tableName,
        Item: {
            userId: "test",
            noteId: uuid.v1(),
            content: data.content,
            attachment: data.attachment,
            createdAt: Date.now()
        }
    };

    await dynamoDb.put(params);

    return params.Item;
});

Worked for me Thanks!!!

This might be happening if the user is not being logged in correctly or if the Identity Pool has not be setup. If you were to print out event.requestContext.identity, what do you see?

I tested my APIs some time ago, now having made more progress, I have come across this error:

  message: 'Only radix 2, 4, 8, 16, 32 are supported'

Any ideas why this would have worked before but doesn’t now … ?

Hi All, I managed a workaround using the following format for the --body JSON

body=’{“content”:“helloworld”,“attachment”:“hello.jpg”}’

notice that all the double quote’s are escaped using \ and the space has been removed from helloworld

1 Like

@jayair Everything is null

{
  cognitoIdentityPoolId: null,
  accountId: null,
  cognitoIdentityId: null,
  caller: null,
  sourceIp: 'validIP',
  principalOrgId: null,
  accessKey: null,
  cognitoAuthenticationType: null,
  cognitoAuthenticationProvider: null,
  userArn: null,
  userAgent: 'axios/0.18.1',
  user: null
}

And now I found my mistake, finally, after 20 days. I types authporizer instead of authorizer for the create endpoint, and I probably checked the file 10 times but somehow failed to see that…still thanks for the help here.

1 Like