要解决API网关未将路径参数转发到VPC Link集成的URI的问题,需要进行以下步骤:
确保API网关配置正确,其中VPC Link集成已正确设置,并且资源路径参数已正确映射到集成URI。
如果您是使用AWS CloudFormation创建API网关,请确保在CloudFormation模板中正确设置了路径参数的映射。以下是一个示例:
"Resources": {
"MyApiGateway": {
"Type": "AWS::ApiGateway::RestApi",
"Properties": {
"Name": "MyApiGateway",
"Body": {
"swagger": "2.0",
"paths": {
"/{resourceId}": {
"get": {
"x-amazon-apigateway-integration": {
"type": "http_proxy",
"httpMethod": "GET",
"uri": {
"Fn::Sub": "http://${VpcLink}/resources/${resourceId}"
},
"connectionType": "VPC_LINK",
"connectionId": {
"Ref": "MyVpcLink"
}
}
}
}
}
}
}
},
"MyVpcLink": {
"Type": "AWS::ApiGateway::VpcLink",
"Properties": {
"Name": "MyVpcLink",
"TargetArns": [
{
"Ref": "MyEndpoint"
}
]
}
},
"MyEndpoint": {
"Type": "AWS::EC2::VPCEndpoint",
"Properties": {
"ServiceName": "com.amazonaws.us-west-2.execute-api",
"VpcEndpointType": "Interface",
"VpcId": {
"Ref": "MyVpc"
}
}
},
"MyVpc": {
"Type": "AWS::EC2::VPC",
"Properties": {
"CidrBlock": "10.0.0.0/16"
}
}
}
在上面的示例中,/{resourceId}
路径参数被映射到VPC Link集成的URI中。确保路径参数正确地与集成URI进行了替换。
如果您正在使用自定义的代理集成,确保您的代理服务器正确处理路径参数,并将它们传递到VPC Link集成的URI。
如果上述步骤都正确配置,但问题仍然存在,请检查您的VPC子网和路由表设置,确保API网关可以访问VPC Link集成的URI。
请注意,上述示例代码是使用AWS CloudFormation进行API网关和VPC Link集成的示例。如果您使用其他方式进行配置,请相应地调整配置和代码。