如何解决API网关-消息“选择集成响应”使用cloudformation创建堆栈时
这是我期望在创建堆栈后在API Gateway中看到的内容。
但这是实际发生的情况。
在方法响应中,它显示消息“选择积分响应”,但是
我确实在方法响应中添加了模型,并且应该显示“ HTTP状态:代理”
发生了什么事?
resources.json
{
"AWstemplateFormatVersion": "2010-09-09","Resources": {
"HelloWorldApi": {
"Type": "AWS::ApiGateway::RestApi","Properties": {
"Name": "hello-api","Description": "API used for practice","FailOnWarnings": true
}
},"getBannerMethod": {
"Type": "AWS::ApiGateway::Method","DependsOn": ["HelloWorldApi"],"Properties": {
"RestApiId": {
"Ref": "HelloWorldApi"
},"ResourceId": {
"Ref": "BannerResource"
},"HttpMethod": "GET","MethodResponses":[
{
"ResponseModels" : {"application/json" : "Empty"},"ResponseParameters":{
"method.response.header.Access-Control-Allow-Origin": "'*'"
},"StatusCode" : "200"
},{
"StatusCode": "500"
}
],"AuthorizationType": "NONE","Integration": {
"Credentials": {
"Fn::ImportValue": {
"Fn::Sub": "${Rolesstack}-ApiGatewayRoleArn"
}
},"IntegrationHttpMethod": "POST","Type": "AWS_PROXY","Uri": {
"Fn::Join": ["",[
"arn:aws:apigateway:",{
"Ref": "AWS::Region"
},":lambda:path/2015-03-31/functions/",{
"Fn::GetAtt": ["getBannerHandler","Arn"]
},"/invocations"
]
]
}
}
}
}
}
}
解决方法
只需将其添加到Integration
内:
"IntegrationResponses": [{
"ResponseParameters":{
"method.response.header.Access-Control-Allow-Origin": "'*'"
},"StatusCode" : "200"
}]
下面的方块
"MethodResponses":[
{
"ResponseModels" : {"application/json" : "Empty"},"ResponseParameters":{
"method.response.header.Access-Control-Allow-Origin": "'*'"
},"StatusCode" : "200"
},{
"StatusCode": "500"
}
],
设置为方法响应级别。您正在查看的lambda表示集成响应级别。为此,您必须设置IntegrationResponses
。
完整模板:
{
"AWSTemplateFormatVersion": "2010-09-09","Resources": {
"HelloWorldApi": {
"Type": "AWS::ApiGateway::RestApi","Properties": {
"Name": "hello-api","Description": "API used for practice","FailOnWarnings": true
}
},"getBannerMethod": {
"Type": "AWS::ApiGateway::Method","DependsOn": ["HelloWorldApi"],"Properties": {
"RestApiId": {
"Ref": "HelloWorldApi"
},"ResourceId": {
"Ref": "BannerResource"
},"HttpMethod": "GET","MethodResponses":[
{
"ResponseModels" : {"application/json" : "Empty"},"AuthorizationType": "NONE","Integration": {
"Credentials": {
"Fn::ImportValue": {
"Fn::Sub": "${RolesStack}-ApiGatewayRoleArn"
}
},"IntegrationHttpMethod": "POST","IntegrationResponses": [{
"ResponseParameters":{
"method.response.header.Access-Control-Allow-Origin": "'*'"
},"StatusCode" : "200"
}],"Type": "AWS_PROXY","Uri": {
"Fn::Join": ["",[
"arn:aws:apigateway:",{
"Ref": "AWS::Region"
},":lambda:path/2015-03-31/functions/",{
"Fn::GetAtt": ["getBannerHandler","Arn"]
},"/invocations"
]
]
}
}
}
}
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。