这对后端来说是一件非常痛苦的事情,浪费了数小时,而且仍然无法弄清楚 AWS CloudFormation 的一行语法。
如果 AWS 人员可以稍微写得更好一点 - 只要多花一点注意力 - 这对开发人员来说会更容易。
我正在尝试使用 CloudFormation 来部署具有 VPC Link 和 NLB 的 API Gateway。目标是将所有请求代理传递到 NLB:
ApiProxyMethod:
Type: AWS::ApiGateway::Method
Properties:
RestApiId: !Ref ApiGatewayRestApi
ResourceId: !Ref ApiProxyResource
# AuthorizationScopes: # https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-method.html#cfn-apigateway-method-authorizationscopes
AuthorizationType: COGNITO_USER_POOLS
AuthorizerId: !Ref ApiAuthorizer
HttpMethod: ANY
OperationName: "ProxyAllRequests"
Integration:
ConnectionType: VPC_LINK
ConnectionId: !Ref ApiGatewayVpcLink
IntegrationHttpMethod: ANY
PassthroughBehavior: String
Type: "VPC_LINK" # Member must satisfy enum value set: [HTTP, AWS_PROXY, HTTP_PROXY, AWS]
Uri: "http://NLB-myapp-internal-beta-12345.elb.ap-northeast-1.amazonaws.com/{proxy}"
但是,这会失败,并且会提示错误的 Type
值:成员必须满足枚举值集:[HTTP、AWS_PROXY、HTTP_PROXY、AWS]
现在,其中哪一个适用于 VPC_Link/NLB?
他们本可以在 AWS::ApiGateway::Method Integration
的文档中列出这些值,但他们选择不这样做。
最佳答案
为了将所有请求代理传递到 NLB,您需要将 Type
字段指定为 HTTP_PROXY
Here您可以找到有关集成参数的更多有用文档
ApiProxyMethod:
Type: AWS::ApiGateway::Method
Properties:
RestApiId: !Ref ApiGatewayRestApi
ResourceId: !Ref ApiProxyResource
AuthorizationType: COGNITO_USER_POOLS
AuthorizerId: !Ref ApiAuthorizer
HttpMethod: ANY
OperationName: "ProxyAllRequests"
Integration:
ConnectionType: VPC_LINK
ConnectionId: !Ref ApiGatewayVpcLink
IntegrationHttpMethod: ANY
PassthroughBehavior: String
Type: HTTP_PROXY
Uri: "http://NLB-myapp-internal-beta-12345.elb.ap-northeast-1.amazonaws.com/{proxy}"
关于amazon-web-services - AWS Cloudformation - 如何将 vpc 链接/NLB 附加到 api 网关中的方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72014326/