rustyskates
rustyskates

Reputation: 866

How can I create a AWS APIGateway Custom Authorizer using stage variables in Terraform?

I see that AWS ApiGateway now provides the ability to pass stage variables to a custom authorizer lambda in the console, by selecting the 'Request' type payload and listing the variables that should be passed though.

However, we create our AWS resources exclusively via Terraform (no manual intervention allowed), and the Terraform docs currently say:

type - (Optional) The type of the authorizer. TOKEN is currently the only allowed value. Defaults to TOKEN.

Is there some way to force the payload type to be 'REQUEST' programmatically, and pass in stage variables?

Upvotes: 0

Views: 1222

Answers (1)

rustyskates
rustyskates

Reputation: 866

You can actually do this through Terraform, despite what the docs say.

Just set the type to REQUEST, and pass the stage variables (and/or headers, and/or query strings) in a comma-separated list like this: "method.request.header.SomeHeaderName,method.request.querystring.SomeQueryStringName,stageVariables.SomeStageVariableName" etc:

resource "aws_api_gateway_authorizer" "api-gateway-auth" {
  ...
  type            = "REQUEST"
  identity_source = "method.request.header.SomeHeaderName,method.request.querystring.SomeQueryStringName,stageVariables.SomeStageVariableName"
  ...
}

Upvotes: 4

Related Questions