无法使用Cloudformation为websocket路由集成请求定义集成类型'VPC link‘。
我们不使用无服务器,但有现有的微服务提供websocket功能。这些微服务运行在内网,并且只能通过VPC链路连接到运行它们的EKS集群。
所有与AWS API网关/websockets相关的在线Cloudformation示例都使用无服务器集成。
我可以使用AWS控制台手动配置集成类型"VPC link“,但似乎不支持使用Cloudformation这样做。或者至少完全不清楚如何实现这一点。
Cloudformation文档还明确指出,对于AWS::APIGatewayV2::Integration.ConnectionType,唯一可用的类型是"INTERNET“,而不是"VPC_LINK”。
任何人知道这是否可以实现,如果不是,我有什么其他选择来自动化这一点?
基础设施是使用Terraform设置的,由于缺乏对API Gateway/websockets的支持,我已经需要“后退”到CloudFormation,但看起来CloudFormation还不能支持所有东西。
发布于 2021-05-20 16:26:21
恐怕我也有类似的问题。我无法使用VPC Link创建与私有ALB的API网关Websocket API集成(http集成)。
我可以使用cloudFormation成功集成Api Gateway HTTP API和内部ALB,按照this使用VPC链路。
但是,尽管根据documentation,AWS::APIGatewayV2::Integration.ConnectionType同时支持INTERNET和VPC_LINK,但它似乎不起作用,云形成堆栈失败,并出现以下错误:
VpcLink V2 are not supported for WEBSOCKET Apis. Only Http Apis are supported. (Service: AmazonApiGatewayV2; Status Code: 400; Error Code: BadRequestException关于我如何尝试的云形成示例
websocketApiGateway:
Type: AWS::ApiGatewayV2::Api
Properties:
Name: websocket-gateway
Description: Api Gateway for websocket
ProtocolType: WEBSOCKET
RouteSelectionExpression: $request.body.action
connectRoute:
Type: AWS::ApiGatewayV2::Route
Properties:
ApiId: !Ref websocketApiGateway
RouteKey: $connect
AuthorizationType: NONE
OperationName: ConnectRoute
RouteResponseSelectionExpression: $default
Target: !Join
- /
- - integrations
- !Ref connectIntegration
connectIntegration:
Type: AWS::ApiGatewayV2::Integration
Properties:
ApiId: !Ref websocketApiGateway
Description: Websocket $connect integration
IntegrationType: HTTP_PROXY
IntegrationMethod: ANY
ConnectionType: VPC_LINK
ConnectionId: !Ref privateLink
IntegrationUri: # with VPC_LINK I can't use a well formed url, it's necessary to use the ALB's ARN
Fn::ImportValue: alb-http-listener-id
RequestParameters:
"integration.request.header.domainName": "context.domainName"
"integration.request.header.stage": "context.stage"
"integration.request.header.connectionId": "context.connectionId"
PayloadFormatVersion: 1.0
privateLink:
Type: AWS::ApiGatewayV2::VpcLink
Properties:
Name: private-link
SecurityGroupIds:
- !Ref securityGroup
SubnetIds:
- !Ref privateNetworkA
- !Ref privateNetworkB
- !Ref privateNetworkC如果任何人有进一步的信息,请一定要张贴。这种缺乏支持和令人困惑的文档是不幸的。
发布于 2021-10-21 10:29:42
我偶然发现了同样的问题。我想我是通过使用阶段变量来解决这个问题的,就像API Gateway web控制台建议的那样。因此,您需要将ConnectionID设置为字符串${stageVariables.vpcLinkId}。您需要创建一个AWS::ApiGatewayV2::Stage资源,该资源具有一个名为vpcLinkId的阶段变量,并包含VPC链路的ID (您可以对其执行!Ref操作)。最后,需要使用附加有IntegrationUri的DNS名称的http://来设置/构造ALB。这将使您能够成功创建VPC集成。
我仍然在弄清楚IntegrationType应该是HTTP还是HTTP_PROXY,以及是否需要创建请求和/或响应模板。但这是另一个问题:-)
https://stackoverflow.com/questions/56775948
复制相似问题