Search code examples
amazon-web-servicesaws-lambdaaws-api-gateway

Api gateway invoking a lambda returns 403


I've recently migrated a local python script to lambda via aws cdk. It collects data from an public api endpoint. On my local machine this function works 100% of the time when it comes to status codes and responses from the api.

When the code is running within the lambda alone its also working fine, 100% of requests are returning with 200.

When the lambda is invoked by an api gateway it will fail with a 403?

Other info

  • api is public and requires no auth
  • all deployed with AWS CDK 2
  • gateway has no issues accessing the lambda as the debugging comes back correctly formatted
  • Lambda works with HTTP 200 when testing via console
  • API Gateway fails with 403 when testing via the console
  • API Gateway fails with 403 when testing via curl on local machine

Solution

  • EDIT: This is likely very unhelpful for the masses and is basically user error at this point.

    In this case my internal lambda logic was causing an occasional malforming to happen one of the parameters within shared scripts.

    This caused the 3rd party during processing to inconsistently return 403.

    Still unsure why this always worked on local tho....