68

I created an api-gateway to put data in my s3 bucket. When I test it in console it works with no problem. Even when I test my token in the authorizer test it returns an "Allow", so there's nothing wrong with my token. My token validation is

^Bearer [-0-9a-zA-z\.]*$

so my python code for generating my header looks like this:

headers = {
    "Authorization": "Bearer " + token,
    "Content-type": "application/json"
}

The rest of my code is:

response = requests.post(url, headers=headers, data={"id":"0678a93d-ee8c-4db5-a831-1e311be4f04b", "test":"12345"})
print(response.text)

The error message I get is "{"message":"'{My Token}' not a valid key=value pair (missing equal-sign) in Authorization header: 'Bearer {My Token}'."}"

My url looks like this:

https://my-api-gateway.amazonaws.com/MyStage, and I am using a {proxy+} in my resources. I noticed if I change my header from Content-type to Accept, it gives me the same error, but if I also change my url to https://my-api-gateway.amazonaws.com/MyStage/any-arbitrary-string/, I get a

   {"response":{"status":"VALID", "message": "success"}} 

but the file does not show up in my s3 bucket. How do I resolve this?

Tesuji
  • 1,335
  • 2
  • 12
  • 26
  • Do you have `AWS_IAM` enabled on the S3 Bucket? If so then that requires your request be signed with [AWS Signature Version 4](https://docs.aws.amazon.com/general/latest/gr/signature-version-4.html). – tbejos Jul 23 '19 at 16:11
  • I don't recall enabling that. How do I check/verify this? – Tesuji Jul 23 '19 at 16:13
  • I believe that if you use any user other than the main user you have it enabled as it is a user property. Here is more [info on IAM](https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction.html) and here is how to [call the API while using IAM](https://docs.aws.amazon.com/IAM/latest/UserGuide/programming.html). – tbejos Jul 23 '19 at 16:38

14 Answers14

81

I have run across this error when the resolved URL was incorrect. (Or without a proxy but with an incorrect URL.)

Will
  • 6,601
  • 3
  • 31
  • 42
  • 10
    Also, check the method. It might be POST instead of GET, etc. – RaisinBranCrunch Jan 08 '21 at 19:53
  • 19
    Web development has been around for so long. Why can't they make clear, accurate error messages? Anyway, thanks, this was the solution for my issue. – Max Wilder May 07 '21 at 22:06
  • 6
    Cannot thank you enough: the AWS error message was hopeless debugging this. Lesson learned; don't trust the docs blindly. – thoroc Oct 12 '21 at 15:38
  • Still happens to me when I forget to add "v1" to the base URL in Postman. – ob-ivan Jun 16 '23 at 17:17
  • also caused by incorrect URL on my end, forgot a / in the middle. still an unexpected error message though. – F.E.A Jun 30 '23 at 08:58
18

For me the reason why it didn't work is because I didn't redeploy when making changes to the integration.

So if you use terraform to create resources, you need to include the triggers part. See: https://www.terraform.io/docs/providers/aws/r/api_gateway_deployment.html#redeployment-triggers

If you're using UI, check: enter image description here

Tommy Nguyen
  • 3,403
  • 1
  • 15
  • 14
8

I resolved it. I changed my method to come from the root resource (instead of the unnecessary {proxy+}, and also noticed that my python method was incorrect. I had response = requests.post(url, headers=headers, data=my_json), but data only accepts a string. I have to use either requests.post(url, headers=headers, json=my_json) or requests.post(url, headers=headers,data=json.dumps(my_json))

Simply Ged
  • 8,250
  • 11
  • 32
  • 40
Tesuji
  • 1,335
  • 2
  • 12
  • 26
5

I had faced the same issue. For me, the issue was due to a case-sensitive url. Please make sure, the spelling and the casing of each of the words are correct.

Avinandan
  • 61
  • 1
  • 2
3

in my case very similar, using third api payment has wrong set on request METHOD , instead of DELETE I use POST. ah my bad.

lpacheco
  • 976
  • 1
  • 14
  • 27
Yogi Arif Widodo
  • 563
  • 6
  • 22
2

When using "{proxy+}" in the path, you also need to add a root path. Adding "{proxy+}" is how api gateway knows you are using Lambda proxy integration. So don't leave it out.

viz.,

Type: AWS::Serverless::Function
    Properties:
       Events:
         ProxyResource:
           Type: Api
           Properties:
             RestApiId: ...
             Path: /{proxy+}
             Method: ANY
         RootResource:
           Type: Api
           Properties:
             RestApiId: ...
             Path: /
             Method: ANY
ravi
  • 949
  • 11
  • 22
1

for postman code generator , please make sure to remove unnecessary spaces from the URL , that was my issue

hamza felix
  • 39
  • 1
  • 4
1

If you are using aws-api-gateway.
if the api is working fine in api-gateway of aws console and not working in the postman.

chances are you might have forgotten to deploy your api in api gateway

abhish
  • 243
  • 4
  • 8
0

I had the same error when just running AWS.config.update. I had an extra space character and it gave this error. Just posting it here as it wasn't clear - but easily discoverable I am sure.

Sean
  • 1,151
  • 3
  • 15
  • 37
0

In my case, I chose wrong method. Please check your request method

0

For me, the issue was similarly an incorrect URL. My endpoint was meant to accept another URL as a path argument; and I'd applied Pyton's urllib.parse.quote(url) instead of urllib.parse.quote_plus(url), so I was making requests to https://apigw.playground.sweet.io/gameplay/pack/https%3A//collectible.playground.sweet.io/series/BjqGOJqp instead of https://apigw.playground.sweet.io/gameplay/pack/https%3A%2F%2Fcollectible.playground.sweet.io%2Fseries%2FBjqGOJqp

kokociel
  • 497
  • 6
  • 17
0

When I got this, I was being braindead and was hitting the apigateway root, and not an endpoint with a handler.

TWitt
  • 61
  • 4
0

in my case it worked when I replaced POST by PATCH

curl_setopt_array($curl, array(
...
CURLOPT_CUSTOMREQUEST => 'PATCH',
...
Ben
  • 188
  • 2
  • 16
0

Along with Will's answer, please also ensure the URL that you are calling is same case (lowercase or otherwise) as defined in API Gateway. The URL is case-sensitive

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/33935738) – xlmaster Mar 04 '23 at 11:41