Use timestamp in AWS API Gateway in the Path Overr

2019-08-01 11:08发布

I've been trying to create a method in API Gateway that drops the body of the incoming request into a file/object in an S3 bucket. But I want the method to create a new file each time (so a file with a new name) instead of overwriting the previous one. But I've been struggling to find a way to do it. Anyone has any suggestions/ideas? Something like a timestamp, or a sequence number (or both) to use as a variable in the Path override so that it would become the name of the s3 file. I looked at suggestions to use the X-Amzn-Trace-Id but it doesn't seem to be available in Path override. Anything else I could try? Maybe something in Swagger? I want to achieve it using API Gateway (avoid using a lambda as an extra step) to keep our architecture from getting too complex. Thanks in advance!

1条回答
可以哭但决不认输i
2楼-- · 2019-08-01 11:32

You can set the X-Amzn-Trace-Id as the method parameter, then map the parameter to the integration parameter on the path to S3 as the object name .

Example:

---
swagger: "2.0"
info:
  version: "2017-12-04T23:03:26Z"
  title: "API"
host: "xxxx.execute-api.us-east-1.amazonaws.com"
basePath: "/dev"
schemes:
- "https"
paths:
  /:
    post:
      produces:
      - "application/json"
      parameters:
      - name: "X-Amzn-Trace-Id"
        in: "header"
        required: false
        type: "string"
      responses:
        200:
          description: "200 response"
          schema:
            $ref: "#/definitions/Empty"
      x-amazon-apigateway-integration:
        credentials: "arn:aws:iam::178779171625:role/api-gate-way"
        responses:
          default:
            statusCode: "200"
        requestParameters:
          integration.request.path.traceid: "method.request.header.X-Amzn-Trace-Id"
        uri: "arn:aws:apigateway:us-east-1:bucketName.s3:path/{traceid}"
        passthroughBehavior: "when_no_match"
        httpMethod: "PUT"
        type: "aws"
definitions:
  Empty:
    type: "object"
    title: "Empty Schema"
查看更多
登录 后发表回答