如何在cloudformation中将模板添加到APIgateway(in integrationResponse)的映射模板body
How to add template to body Mapping Templates of APIgateway(in integrationResponse)in cloudformation
我正在使用 api 网关,在我的集成响应的 body 映射模板中我有:
#set ($errorMessageObj = $util.parseJson($input.path('$.errorMessage')))
#set ($bodyObj = $util.parseJson($input.body))
{
"searchObjects":"$input.body",
"statusCode":"$errorMessageObj.statusCode",
"message":"$errorMessageObj.message"
}
现在在我的代码的 api 网关部分我有:
GetMethod:
Type: AWS::ApiGateway::Method
DependsOn: APIGatewayToLambdaPermission
Properties:
AuthorizationType: NONE
HttpMethod: GET
Integration:
Type: AWS
IntegrationHttpMethod: POST
Uri:
Fn::Join:
- ''
- - 'arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/'
- Fn::ImportValue: !Sub ${project}-${EnvironmentApp}-lambda-es-
search
- "/invocations"
IntegrationResponses:
- StatusCode: 200
ResponseParameters:
method.response.header.Access-Control-Allow-Origin: "'*'"
我不知道如何将其添加到我的云层中:
#set ($errorMessageObj = $util.parseJson($input.path('$.errorMessage')))
#set ($bodyObj = $util.parseJson($input.body))
{
"searchObjects":"$input.body",
"statusCode":"$errorMessageObj.statusCode",
"message":"$errorMessageObj.message"
}
这是我的 api 网关设置:
有什么想法吗?
如果您使用过 AWS 控制台,您可以前往
API Gateway > api > stage > tab Export >
choose Export as Swagger + API Gateway Extensions > click on YAML
比你所见
httpMethod: "POST"
requestTemplates:
application/json: "#set ($errorMessageObj = $util.parseJson($input.path('$.errorMessage')))\n\
#set ($bodyObj = $util.parseJson($input.body))\n\n {\n \"searchObjects\"\
:\"$input.body\",\n \"statusCode\":\"$errorMessageObj.statusCode\",\n\
\ \"message\":\"$errorMessageObj.message\"\n }"
contentHandling: "CONVERT_TO_TEXT"
type: "aws"
希望对您有所帮助
我正在使用 api 网关,在我的集成响应的 body 映射模板中我有:
#set ($errorMessageObj = $util.parseJson($input.path('$.errorMessage')))
#set ($bodyObj = $util.parseJson($input.body))
{
"searchObjects":"$input.body",
"statusCode":"$errorMessageObj.statusCode",
"message":"$errorMessageObj.message"
}
现在在我的代码的 api 网关部分我有:
GetMethod:
Type: AWS::ApiGateway::Method
DependsOn: APIGatewayToLambdaPermission
Properties:
AuthorizationType: NONE
HttpMethod: GET
Integration:
Type: AWS
IntegrationHttpMethod: POST
Uri:
Fn::Join:
- ''
- - 'arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/'
- Fn::ImportValue: !Sub ${project}-${EnvironmentApp}-lambda-es-
search
- "/invocations"
IntegrationResponses:
- StatusCode: 200
ResponseParameters:
method.response.header.Access-Control-Allow-Origin: "'*'"
我不知道如何将其添加到我的云层中:
#set ($errorMessageObj = $util.parseJson($input.path('$.errorMessage')))
#set ($bodyObj = $util.parseJson($input.body))
{
"searchObjects":"$input.body",
"statusCode":"$errorMessageObj.statusCode",
"message":"$errorMessageObj.message"
}
这是我的 api 网关设置:
有什么想法吗?
如果您使用过 AWS 控制台,您可以前往
API Gateway > api > stage > tab Export > choose Export as Swagger + API Gateway Extensions > click on YAML
比你所见
httpMethod: "POST"
requestTemplates:
application/json: "#set ($errorMessageObj = $util.parseJson($input.path('$.errorMessage')))\n\
#set ($bodyObj = $util.parseJson($input.body))\n\n {\n \"searchObjects\"\
:\"$input.body\",\n \"statusCode\":\"$errorMessageObj.statusCode\",\n\
\ \"message\":\"$errorMessageObj.message\"\n }"
contentHandling: "CONVERT_TO_TEXT"
type: "aws"
希望对您有所帮助