I have an AWS REST API Gateway whose Authorization in “Method request settings” is “Cognito-auth”.
When I use the “Test” tab in “Method request” to test the API Gateway, it can successfully return a 200 status code.
But when I send the same request to the API gateway using curl
command, I got and 401 Unauthorized
error. Does anyone know why?
Here’s my curl
command:
curl --include 'https://asdfadsf.execute-api.<my-region>.amazonaws.com/dev/api/v1/dosomething'
-X POST
-H 'authorization: asdfasdfasdfasdf'
--data-raw '{"foo":1,"bar":20}'
Here’s its returned message:
HTTP/2 401
date: Mon, 13 May 2024 10:10:08 GMT
content-type: application/json
content-length: 26
x-amzn-requestid: 7595d74b-8ef6-45e7-8eb0-32165747q
access-control-allow-origin: *
access-control-allow-headers: Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token
x-amzn-errortype: UnauthorizedException
x-amz-apigw-id: asdfasdf=
access-control-allow-methods: DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT
What might be wrong with my API gateway? I’ve deployed the API gateway to the dev
stage. Which is the only stage I have in the API gateway.
I also got 401 Unauthorized
when my browser send the same request to the API gateway.
I really have no idea what went wrong with the API gateway.