【问题标题】:AWS Api gateway write to S3 with timestamp as filenameAWS Api 网关以时间戳作为文件名写入 S3
【发布时间】:2018-10-31 04:00:22
【问题描述】:

我正在尝试在 Api Gateway 上创建一个端点,该端点使用 data/$timestamp 之类的文件名写入 AWS s3 存储桶,其中时间戳是每个请求中应该可用的 $context.requestTimeEpoch 变量

我的api网关请求集成是这样的

{
    "type": "AWS",
    "httpMethod": "PUT",
    "uri": "arn:aws:apigateway:eu-west-1:bucketname.s3:path/data/{reqTimestamp}",
    "credentials": "arn:aws:iam::xxxxx:role/ApiGatewayWriteToDemoS3Bucket",
    "requestParameters": {
        "integration.request.path.reqTimestamp": "context.requestTime"
    },
    "passthroughBehavior": "WHEN_NO_MATCH",
    "timeoutInMillis": 29000,
    "cacheNamespace": "5f92eajcg9",
    "cacheKeyParameters": [],
    "integrationResponses": {
        "200": {
            "statusCode": "200",
            "responseParameters": {
                "method.response.header.Access-Control-Allow-Origin": "'*'"
            },
            "responseTemplates": {
                "application/json": null
            }
        }
    }
}

但是我得到了这个错误

Execution failed due to configuration error: Illegal character in path at index 49: https://bucketname.s3-eu-west-1.amazonaws.com/data/{reqTimestamp}

它只工作了一次,然后我遇到了 S3 身份验证错误,但这是另一回事

【问题讨论】:

    标签: amazon-web-services aws-api-gateway


    【解决方案1】:

    您需要在您的API网关资源方法的集成请求的URL路径参数配置中添加一个值,设置名称为reqTimestamp,值设置为method.request.path.reqTimestamp

    这会将 API Gateway 在 URL 中接收到的值映射到您定义的路径覆盖参数。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-07
      • 2023-03-11
      • 1970-01-01
      • 2011-11-21
      • 1970-01-01
      相关资源
      最近更新 更多