Search code examples
amazon-web-servicesaws-lambdaaws-api-gatewaycustom-authentication

Change my AWS API Gateway Custom Authorizer per stage


I currently have an API going through our API Gateway, which has multiple Custom Authorizers attached - LiveAuthorizer and TestAuthorizer.

I'd like to change my custom authorizer based on the stage being accessed, just like a stage variable. If we are in stage Test, use the TestAuthorizer, if in live use the LiveAuthorizer.

From my research and this page it doesn't seem possible, any ideas?

PS - I know this could be handled from within the Lambda function doing the authentication, I'm just curious if there is another way (similar to stage variables).


Solution

  • You can use a stage variable in a single Authorizer to point to different Lambda functions depending on the stage, but you cannot point to different Authorizers.

    In a lot of cases pointing to a different Lambda function works. The other settings on the Authorizer (like the header source or the TTL) don't support stage variables so those would have to be shared by all stages.

    Edit: I should explain, a key reason for not allowing this is the fact that our stage variable feature as-is doesn't have a fallback if at runtime the variable doesn't exist. Since running an Authorizer is critical, we would have to come up with a different mechanism similar to stage variables with a built-in safety mechanism.