Skip to content

API Gateway http header Bearer Token Lambda Authorization

0

This is my problem, I believe it points to permission error, but I don't know where the chain is broken Enter image description here

The Authorizer Test Passes Enter image description here

If I execute it without Authorization, I get a response

Enter image description here

If I execute with Authorization, I can see the authorization being accepted in the logs and then it fails Enter image description here

Role is assigned to execute Authorization Lambda. Lambda is executing like it should validating the Bearer key being passed, I can see if it Accepted or denied in the logs. It seems the Authorization gets approved and the permission is passed back as you can see in the Authorizer Test logs.

I'm at a loss here.

**Additional infomation: **I made sure the lambda after authorization had resource-based permissions to be invoked by api-gateway and it does: Enter image description here

Confirmed the correct policy is being passed back upon authorization Enter image description here

Is there anyway to get more information for this? I'd like to know the details of what happened there. Enter image description here

2 Answers
0

Based on your screenshots and description, this appears to be a permissions issue between API Gateway and your endpoint Lambda (not the authorizer Lambda). Here's how to fix it:

  1. Check your endpoint Lambda's resource policy. Add permission for API Gateway to invoke it:
aws lambda add-permission \
  --function-name "your-endpoint-lambda-name" \
  --statement-id "api-gateway-permission" \
  --action "lambda:InvokeFunction" \
  --principal "apigateway.amazonaws.com" \
  --source-arn "arn:aws:execute-api:region:account-id:api-id/*/*/*"
  1. Or add it through the AWS Console:

    • Go to your endpoint Lambda
    • Select 'Configuration' > 'Permissions'
    • Check resource-based policy
    • Add permission for API Gateway
  2. Verify the API Gateway role has:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": "lambda:InvokeFunction",
            "Resource": "arn:aws:lambda:region:account-id:function:your-lambda-function"
        }
    ]
}

The authorizer is working (as shown by your test), but API Gateway can't invoke your endpoint Lambda after authorization succeeds. This is a separate permission from the authorizer Lambda permissions.

For more details, see: API Gateway Permissions Documentation

AWS

answered a year ago

EXPERT

reviewed a year ago

  • I appreciate you time. I didn't have that resource-based permission set up. So I added it and same result. I confirmed in the logs that the correct policy is being passed back from authorization and it is.

0

Based on the information provided, it appears that you're experiencing an issue with API Gateway Lambda authorization. The problem seems to occur after the authorization is successful, suggesting that the issue may lie in how the authorized request is being handled or passed to the backend.

Here are some potential areas to investigate:

  1. Lambda Function Permissions: Ensure that the Lambda function associated with your API endpoint (not the authorizer) has the necessary permissions to be invoked by API Gateway. Check the function's resource-based policy to confirm it allows API Gateway to invoke it.

  2. API Gateway Configuration: Verify that the integration between API Gateway and your backend Lambda function is set up correctly. This includes checking the integration type, Lambda function ARN, and execution role.

  3. IAM Roles: Review the IAM role attached to your API Gateway. Make sure it has the necessary permissions to invoke the Lambda function.

  4. Lambda Authorizer Configuration: Double-check the Lambda authorizer settings in API Gateway. Ensure that the authorizer is correctly configured to pass the necessary context to the backend, including any required claims or principal identifiers.

  5. CORS Settings: If your API is being called from a different domain, verify that CORS is properly configured in API Gateway.

  6. API Gateway Stages: Confirm that your API is deployed to the correct stage and that the stage variables (if any) are properly set.

  7. Lambda Function Error Handling: Review the error handling in your backend Lambda function. It's possible that the function is receiving the request but encountering an error that's not being properly caught or logged.

  8. CloudWatch Logs: Check the CloudWatch logs for both the authorizer Lambda and the backend Lambda function to see if there are any error messages or unexpected behaviors not visible in the API Gateway test console.

  9. API Gateway Method Execution: In the API Gateway console, use the Test feature on the Method Execution page to test each step of the request processing (Method Request, Integration Request, Integration Response, Method Response) to identify at which stage the request is failing.

Given that the authorizer test passes but the actual request fails, it's likely that the issue is occurring after authorization, possibly in how the authorized request is being processed or how it's being passed to your backend Lambda function. Carefully reviewing each of these areas should help you identify and resolve the issue.
Sources
Tutorial verbatim fails with Missing Authentication Token | AWS re:Post
x-amazon-apigateway-authtype property - Amazon API Gateway

answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.