首先,需要在API Gateway中为HTTP端点配置HTTP代理集成。这可以通过以下步骤完成:
下面是一个用Python写的示例代码,展示如何使用AWS SDK for Python (Boto3)将API Gateway HTTP代理请求发送到另一个端点:
import boto3
# 创建API网关客户端
apigateway = boto3.client('apigateway')
# 配置代理请求模板
request_template = {
"path" : "$input.path",
"httpMethod" : "$context.httpMethod",
"headers" : {
"Accept" : "$input.params().header.get('Accept')",
"Content-Type" : "$input.params().header.get('Content-Type')"
},
"queryStringParameters" : "$input.params().querystring",
"body" : "$input.body"
}
# 配置代理响应模板
response_template = {
"status_code" : "$input.path('$').statusCode",
"headers" : {
"Content-Type" : "application/json"
},
"body" : "$input.body"
}
# 创建代理集成
apigateway.put_integration(
restApiId='your_rest_api_id',
resourceId='your_resource_id',
httpMethod='GET',
integrationHttpMethod='GET',
type='HTTP_PROXY',
uri