Bootstrap FreeKB - Amazon Web Services (AWS) - Resolve "Missing Authentication Token"
Amazon Web Services (AWS) - Resolve "Missing Authentication Token"


Let's say Missing Authentication Token is being returned when submitted a POST request to one of your API Gateway Routes. For example, perhaps you have the following API Gateway Route and you are trying to submit a POST request to the API Gateway Route using cURL.

~]$ curl --url https://abcdefg123.execute-api.us-east-1.amazonaws.com/Prod/api/v1 --header 'Content-Type: application/json' --data '{"foo":"bar"}'
{"message":"Missing Authentication Token"}[

 

There are various ways to go about creating an API Gateway Route that routes requests onto a Lambda Function.

 

If you created the API Gateway Route using Serverless Application Model (SAM) app, the sam list endpoints command should return both the /Prod and /Stage URLs of your Serverless Application Model (SAM) apps, the endpoint (/api/v1 in this example) and allowed methods (post in this example).

Missing Authentication Token may be returned if you attempt a POST request to an endpoint that does not include the POST method.

]$ sam list endpoints --template /tmp/sam-app/template.yaml --output json
[
  {
    "LogicalResourceId": "myFunction",
    "PhysicalResourceId": "sam-app-myFunction-MgYCNMibayEZ",
    "CloudEndpoint": "-",
    "Methods": "-"
  },
  {
    "LogicalResourceId": "ServerlessRestApi",
    "PhysicalResourceId": "zulgntw90l",
    "CloudEndpoint": [
      "https://abcdefg123.execute-api.us-east-1.amazonaws.com/Prod",
      "https://abcdefg123.execute-api.us-east-1.amazonaws.com/Stage"
    ],
    "Methods": [
      "/api/v1['post']"
    ]
  }
]

 

If your Serverless Application Model (SAM) app does not include the POST method, you can update your template.yaml file to include the POST method.

Resources:
  myFunction:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: myapp/
      Handler: app.lambda_handler
      Runtime: python3.9
      Architectures:
        - x86_64
      Events:
        myapp:
          Type: Api
          Properties:
            Path: /api/v1
            Method: post

 

And then use the sam sync command to sync this change to AWS Cloud. This is like deploying an updated version of your app.

sam sync --template /tmp/sam-app/template.yaml --stack-name sam-app --no-watch

 

 

 

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 4c5a55 in the box below so that we can be sure you are a human.