在API Gateway中,可以使用AWS CloudFormation将VPC Link和NLB附加到HTTP API的方法中。但是,在这个过程中,您可能会遇到“Invalid method setting path”错误。这个错误通常是由于API Gateway无法正确定位VPC Link或NLB而导致的。
下面是一些可能导致此错误并可能解决此错误的代码示例:
Example VPC_Link resource:
Resources:
MyApiGateway:
Type: 'AWS::ApiGatewayV2::Api'
Properties:
Name: !Sub ${AWS::StackName}-MyApi
ProtocolType: HTTP
CorsConfiguration:
AllowMethods:
- GET
- POST
- PUT
- DELETE
- PATCH
AllowOrigins:
- '*'
MaxAge: 300
MyRoute:
Type: 'AWS::ApiGatewayV2::Route'
Properties:
ApiId: !Ref MyApiGateway
RouteKey: ANY /
Target: integrations/${MyProxyIntegration.Arn}
MyVpcLink:
Type: 'AWS::ApiGatewayV2::VpcLink'
Properties:
Name: !Sub ${AWS::StackName}-MyVpcLink
SecurityGroupIds:
- !Ref InternalSG
SubnetIds:
- !Ref PrivateSubnetOne
- !Ref PrivateSubnetTwo
Example NLB resource:
Resources:
MyNetworkLoadBalancer:
Type: 'AWS::ElasticLoadBalancingV2::LoadBalancer'
Properties:
Name: !Sub ${AWS::StackName}-MyNetworkLoadBalancer
Scheme: internal
Type: network
Subnets:
- !Ref PrivateSubnetOne
- !Ref PrivateSubnetTwo
DependsOn: PrivateSubnetOne
Example MethodSetting resource:
MyHttpApi:
Type: "AWS::ApiGatewayV2::Api"
Properties:
Name: "My-http-api"
ProtocolType: "HTTP"
RouteSelectionExpression: "request.method = $method"
MyIntegration:
Type: "AWS::ApiGatewayV2::Integration"
Properties:
ApiId: !Ref MyHttpApi
Description: "Http 2
上一篇:AWSCloudFormation-将JSON地图作为模板参数载入
下一篇:AWSCloudformation-属性验证失败:[属性值{/RequestParameters/MessageAttributes}与类型{字符串}不匹配]