无法使用云形成在Api网关上使用方法集成映射VPC_LINK

时间:2018-03-07 06:11:59

标签: aws-api-gateway amazon-cloudformation

我使用Cloudformation配置API网关方法以使用VPC Link。

它不起作用。

示例代码如下:

    ProxyResourceANY: 
    Type: AWS::ApiGateway::Method
    Properties:
        RestApiId: !Ref RestApi
        ResourceId: !Ref RestApiResource
        HttpMethod: ANY      
        AuthorizationType: NONE
        Integration:
            Type: HTTP_PROXY
            IntegrationHttpMethod: ANY
            #ConnectionType: VPC_LINK
            #ConnectionId: !Ref VpcLink
            Uri: !Sub http://${LoadBalancerUrl}:8098

CloudFormation错误:

Encountered unsupported property ConnectionId

1 个答案:

答案 0 :(得分:0)

您不能使用!Ref那里,但是您有2种解决方案:

只需使用!Sub而不是!Ref即可:

#ConnectionId: !Sub ${VpcLink}

或更复杂的话,您可以使用舞台变量:

在您的方法中使用阶段变量"${stageVariables.variable}",而不要引用您的VpcLink

ProxyResourceANY: 
Type: AWS::ApiGateway::Method
Properties:
    RestApiId: !Ref RestApi
    ResourceId: !Ref RestApiResource
    HttpMethod: ANY      
    AuthorizationType: NONE
    Integration:
        Type: HTTP_PROXY
        IntegrationHttpMethod: ANY
        ConnectionType: VPC_LINK
        ConnectionId: '${stageVariables.vpcLink}'
        Uri: !Sub http://${LoadBalancerUrl}:8098

然后在创建舞台时设置引用VpcLink的舞台变量:

Stage:
Type: AWS::ApiGateway::Stage
Properties: 
  StageName: 'Stage'
  Variables: 
    VpcLink: !Ref VpcLink