Amazon web services 将专用API网关连接到SAM(AWS IAC)中VPC的正确方法

Amazon web services 将专用API网关连接到SAM(AWS IAC)中VPC的正确方法,amazon-web-services,yaml,serverless,Amazon Web Services,Yaml,Serverless,我正试图通过部署堆栈中已经存在的VPC端点将AWS专用API网关连接到我的VPC,但在控制台中检查时,我没有看到连接 下面是我的YML文件中的一些代码片段 我已从SSM中提取VPC端点,并已确认这是端点ID。 我的VPE端点ID在SSM的“APIGW”下显示为vpce-XXXXXXXXXX 然后,我按照如下方式创建我的私有API网关。它包含一个在此API上面定义的Lambda PrivateApi: Type: AWS::Serverless::Api Properties:

我正试图通过部署堆栈中已经存在的VPC端点将AWS专用API网关连接到我的VPC,但在控制台中检查时,我没有看到连接

下面是我的YML文件中的一些代码片段

我已从SSM中提取VPC端点,并已确认这是端点ID。 我的VPE端点ID在SSM的“APIGW”下显示为vpce-XXXXXXXXXX

然后,我按照如下方式创建我的私有API网关。它包含一个在此API上面定义的Lambda

  PrivateApi:
    Type: AWS::Serverless::Api
    Properties:
      Name: PrivateApi
      StageName: v1
      MethodSettings:
        - HttpMethod: '*'
          ResourcePath: /*/*/*
          LoggingLevel: ERROR
          ThrottlingBurstLimit: 5000
          ThrottlingRateLimit: 10000
      EndpointConfiguration: PRIVATE
      DefinitionBody:
        swagger: 2.0
        info:
          title: PrivateApi
        x-amazon-apigateway-api-key-source: "HEADER"
        schemes:
          - https
        x-amazon-apigateway-policy:
          Version: "2012-10-17"
          Statement:
            -
              Effect: "Allow"
              Principal: "*"
              Action:
                - "execute-api:Invoke"
              Resource: "execute-api:/*"


              Condition:
                StringEquals:
                  aws:sourceVpce: !Ref APIGW 


        paths:
          /{proxy+}:
            x-amazon-apigateway-any-method:
              produces:
              - application/json
              parameters:
              - name: proxy
                in: path
                required: true
                type: string
              x-amazon-apigateway-integration:
                uri:
                  Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HandleSecurityRouter.Arn}/invocations
                httpMethod: POST
                type: aws_proxy
但是,如果我在使用SAM工具成功部署后查看控制台,则API网关未连接到任何VPC端点


如果您能帮助VPC端点通过SAM连接到我的专用API网关,我们将不胜感激

在控制台中制作了一个我需要的版本,并使用“API”->Stages->“Stage”->Export下的AWS“Export as Swagger”功能将其转换回YML后,我发现API Gateway Swagger的一个未记录或难以找到的属性,需要添加该属性以通过VPC端点将专用网关链接到VPC

在你大摇大摆的时候需要的是以下几句话:

      DefinitionBody:
        swagger: 2.0
        ...
        x-amazon-apigateway-endpoint-configuration:
          vpcEndpointIds:
            - !Ref API-Gateway-ID

我在下面添加了一行服务器->url->x-amazon-apigateway-endpoint-configuration,这对我来说很有用:

openapi: "3.0.2"
info:
  title: "APIGW-TEST-01"
  version: "1.0"
servers:
- url: "https://asdf.execute-api.us-east-1.amazonaws.com/{basePath}"
  variables:
    basePath:
      default: "/test"
  x-amazon-apigateway-endpoint-configuration:
    vpcEndpointIds:
    - "vpce-0asdf"
paths:  
...
openapi: "3.0.2"
info:
  title: "APIGW-TEST-01"
  version: "1.0"
servers:
- url: "https://asdf.execute-api.us-east-1.amazonaws.com/{basePath}"
  variables:
    basePath:
      default: "/test"
  x-amazon-apigateway-endpoint-configuration:
    vpcEndpointIds:
    - "vpce-0asdf"
paths:  
...