我正在使用带有swagger的terraform和openAPI规范创建AWS API网关。我需要添加一个请求验证器来验证匹配模式[a-zA-z0-9] {10}的标头。我能够设置基本验证器,检查标头是否为空,但无法验证模式。
"x-amazon-apigateway-request-validators" : {
"full" : {
"validateRequestBody" : true,
"validateRequestParameters" : true,
"validateRequestHeaders" : true
},
"body-only" : {
"validateRequestBody" : true,
"validateRequestParameters" : false
}
},
"x-amazon-apigateway-request-validator" : "full",
"paths": {
"/validation": {
"get": {
"parameters": [
{
"in": "header",
"name": "x-request-id",
"required": true,
"type": "string",
"pattern" : "^[a-z0-9]{10}$"
},
{
"in": "query",
"name": "name",
"required": true,
"type": "string",
"pattern": "^[a-zA-Z]{5}$"
}
]
}
}
请建议是否有任何方法可以实现这一目标
我可以根据您的要求建议解决方法。您可以使用“基于请求”的Lambda authorizer并在Lambda函数中实现验证逻辑。如果您只需要验证一个标头,则可以使用“基于令牌”的Lambda授权器并指定令牌验证正则表达式。
一旦Lambda函数确定传入标头是否有效,它就可以授予对API的访问权限。
你可以看看如何Configure a Lambda Authorizer Using the API Gateway Console。