1
votes

My lambda works locally and returns the JSON.
My API Gateway works locally, i.e. calls the lambda and returns the JSON.

However when I publish my API to my DEV stage and then try to use the invoke url - https://jbpqyp3142.execute-api.us-east-2.amazonaws.com/DEV I get

{"message":"Missing Authentication Token"}

Lambda:

require 'json'

def lambda_handler(event:, context:)
  if event['queryStringParameters'].nil?
    input = 1
  else
    if event['queryStringParameters']['in']
      input = event['queryStringParameters']['in'].to_i
    else
      input = 1
    end
  end
  triple = (input * 3).to_s
  { statusCode: 200, body: JSON.generate("Hello from Lambda! Result is " + input.to_s + " *3 = " + triple) }
end

API Gateway:

enter image description here


I tried to create an 'authorizer' but got the following error:

enter image description here

3
Do I need to create an 'authorizer' perhaps ?Michael Durrant

3 Answers

1
votes

You are making a request to the root url for your endpoint, which was the link amazon provided, however it will not work as you need to specify the resource you are requesting. You see this when you open up the stage and look for the URL inside it, i.e.

enter image description here

Add the path for the resource, e.g.

https://jbpqyp3142.execute-api.us-east-2.amazonaws.com/DEV/tripler


You shouldn't need an authorizer unless you want one for your use case. Read more about API Gateway access control: https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-control-access-to-api.html

I thought your problem might be that you are not signing your requests using SigV4: https://docs.aws.amazon.com/apigateway/api-reference/signing-requests/

However, before writing this answer, I did a quick search to see if there was anything simpler I might be missing and there was. It seems that you are making a request to the root url for your endpoint, but not specifying the resource you are requesting. The top stack overflow result when searching for the error you are receiving explains the problem: https://stackoverflow.com/a/43285585/715780

0
votes

When your api gateway requires an API key you have to pass it in the request header. x-api-key: yourkey

You can check that in Resources - POST - Method Execution of your API.

0
votes

If you are not using any kind of authorization, then "Missing Authentication Token" is an indication that the URL is either incorrect or missing.

  1. It can be incorrect, if you are not passing the proper or complete stage and resource name.

  2. It can also happen if you are using the incorrect HTTP method to invoke the API resource (i.e. you are using a GET instead of POST).

  3. It can be missing issue if your API is not deployed with the latest changes.

Testing the API from the console is not always the best way to verify if the configuration is correct. Try using Postman application or curl -

curl -v -X $HTTP_METHOD https://$API_ID.execute-api.$AWS_REGION.amazonaws.com/$STAGE_NAME/$RESOURCE_NAME