如何使用Terraform中的阶段变量创建AWS APIGateway自定义授权程序?

问题描述 投票:0回答:1

我看到AWS ApiGateway现在提供了通过选择“请求”类型有效负载并列出应该传递的变量来将阶段变量传递给控制台中的自定义授权器lambda的功能。

但是,我们仅通过Terraform创建我们的AWS资源(不允许手动干预),Terraform文档目前说:

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

有没有办法强制有效负载类型以编程方式“请求”,并传入阶段变量?

amazon-web-services aws-api-gateway terraform api-gateway
1个回答
4
投票

你可以通过Terraform实际做到这一点,尽管文档说的是什么。

只需将类型设置为REQUEST,并将逗号分隔列表中的阶段变量(和/或标题和/或查询字符串)传递给:“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"
  ...
}
© www.soinside.com 2019 - 2024. All rights reserved.