Typescript aws cdk-使用SpecRestApi的专用API网关(openAPI 3) 断然的

Typescript aws cdk-使用SpecRestApi的专用API网关(openAPI 3) 断然的,typescript,amazon-web-services,cloud,aws-cdk,Typescript,Amazon Web Services,Cloud,Aws Cdk,以下PR修复了该问题: 修复此问题。您现在可以按如下方式设置endpointType: const api = new apigateway.SpecRestApi(this, 'ExampleRestApi', { apiDefinition: apigateway.ApiDefinition.fromInline(replacedSwagger), endpointTypes: [apigateway.EndpointType.PRIVATE], }); 注意:对于私有端点,您仍然

以下PR修复了该问题:

修复此问题。您现在可以按如下方式设置endpointType:

const api = new apigateway.SpecRestApi(this, 'ExampleRestApi', {
  apiDefinition: apigateway.ApiDefinition.fromInline(replacedSwagger),
  endpointTypes: [apigateway.EndpointType.PRIVATE],
});
注意:对于私有端点,您仍然需要在openApi文件中提供x-amazon-apigateway-policy


原始问题 我正在尝试使用aws cdk来配置一个使用SPECRASTAPI的私有API网关。(openApi 3)

默认情况下,它使用边缘配置创建端点

文档表明我应该在servers部分中使用该对象,但在使用它时,API网关似乎忽略了它

API部分代码没有多少魔力

    const api = new SpecRestApi(this, 'ExampleRestApi', {
      apiDefinition: ApiDefinition.fromInline(replacedSwagger),
      restApiName: `myTest`,
      deploy: false
    });
这里可以找到一个招摇过市的例子:

{
    "openapi": "3.0.1",
    "info": {
        "title": "ismael-test",
        "description": "ismael-test Rest API",
        "version": "1.0.1"
    },
    "servers" : [
        "x-amazon-apigateway-endpoint-configuration": {
            "vpcEndpointIds": [
                "vpce-00111a1111a1aa011"
            ]
        }
    ],
    "paths": {
        "/example": {
            "get": {
                "responses": {
                    "200": {
                        "description": "200 response",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/SampleResponse"
                                }
                            }
                        }
                    }
                },
                "x-amazon-apigateway-integration": {
                    "uri": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/arn:aws:lambda:${AWS::Region}:${AWS::AccountId}::function:ismael-test-st-imr:st-imr/invocations",
                    "responses": {
                        "default": {
                            "statusCode": "200"
                        }
                    },
                    "passthroughBehavior": "when_no_match",
                    "httpMethod": "POST",
                    "contentHandling": "CONVERT_TO_TEXT",
                    "type": "aws_proxy"
                }
            }
        }
    },
    "components": {
        "schemas": {
            "SampleResponse": {
                "title": "Sample Response",
                "type": "object",
                "properties": {
                    "message": {
                        "type": "string"
                    }
                }
            },
            "500Response": {
                "$ref": "#/components/schemas/Error"
            },
            "Error": {
                "type": "object",
                "properties": {
                    "errorCode": {
                        "type": "string"
                    },
                    "message": {
                        "type": "string"
                    }
                }
            }
        }
    },
    "x-amazon-apigateway-policy": {
        "Version": "2012-10-17",
        "Statement": [
            {
                "Effect": "Allow",
                "Principal": "*",
                "Action": [
                    "execute-api:Invoke",
                    "execute-api:GET"
                ],
                "Resource": "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:*",
                "Condition": {
                    "StringEquals": {
                      "aws:sourceVpce": "vpce-00111a1111a1aa011"
                    }
                }
            }
        ]
    }
}
如果使用servers/x-amazon-apigateway-endpoint-configuration部分,部署将失败,并显示以下消息:

提前谢谢


请注意,为了以防万一,vpce id已被修改。

Hi@Ismael,这与问题没有直接关系,但我确实没有在网上找到解决方案。我注意到您已经使用名为“replacedswager”的变量从内联导入了api定义。。我猜你是在操纵swagger文件来注入lambda arn?那样的话,你能给我举个例子吗?我将永远感谢你:)嗨@Ismael,与这个问题没有直接关系,但我真的没有在网上找到解决办法。我注意到您已经使用名为“replacedswager”的变量从内联导入了api定义。。我猜你是在操纵swagger文件来注入lambda arn?那样的话,你能给我举个例子吗?我将永远感激你:)
AmazonApiGateway; Status Code: 400; Error Code: BadRequestException;
Request ID: 12600381-6232-4213-894d-264b7501828b) ```