首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >API网关S3代理-获取部分响应

API网关S3代理-获取部分响应
EN

Stack Overflow用户
提问于 2021-11-19 08:12:08
回答 1查看 148关注 0票数 1

我正在尝试将设置为S3桶的代理。我已经使用了亚马逊指南,并成功地部署了一个API,您可以在其中指定存储桶和资源路径中的对象键--也就是说,对HTTPS://<API>/{bucket name}/{object key}的调用将得到包含相关内容的200个响应。

由于我在S3存储桶上有一些大型文件,所以我想支持字节范围的抓取。如果我直接调用S3,我可以通过GET请求上的范围标头来完成这个任务。我在API代理上也尝试过同样的方法,它似乎忽略了这个参数。我总是收到200的回应与完整的内容。

我是否可以配置API网关来传递范围请求并返回206响应?

我最初的API定义如下所示。

编辑:为了澄清-我知道预先签名的URL是管理较大文件的推荐方法。在这种情况下,这不是我可以选择的。

代码语言:javascript
复制
{
  "openapi": "3.0.1",
  "info": {
    "title": "GenericS3Reader",
    "version": "2016-10-13T23:04:43Z"
  },
  "servers": [
    {
      "url": "https://XXXXXXXXXX.execute-api.eu-west-2.amazonaws.com/{basePath}",
      "variables": {
        "basePath": {
          "default": "/test"
        }
      }
    }
  ],
  "paths": {
    "/{folder}": {
      "get": {
        "parameters": [
          {
            "name": "folder",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "200 response",
            "headers": {
              "Content-Length": {
                "schema": {
                  "type": "string"
                }
              },
              "Date": {
                "schema": {
                  "type": "string"
                }
              },
              "Content-Type": {
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Empty"
                }
              }
            }
          },
          "400": {
            "description": "400 response",
            "content": {}
          },
          "500": {
            "description": "500 response",
            "content": {}
          }
        }
      }
    },
    "/{folder}/{item}": {
      "get": {
        "parameters": [
          {
            "name": "item",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "folder",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "200 response",
            "headers": {
              "content-type": {
                "schema": {
                  "type": "string"
                }
              },
              "Content-Type": {
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Empty"
                }
              },
              "audio/wav": {
                "schema": {
                  "$ref": "#/components/schemas/Empty"
                }
              }
            }
          },
          "400": {
            "description": "400 response",
            "content": {}
          },
          "500": {
            "description": "500 response",
            "content": {}
          }
        }
      },
      "head": {
        "parameters": [
          {
            "name": "item",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "folder",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "200 response",
            "headers": {
              "Content-Length": {
                "schema": {
                  "type": "string"
                }
              },
              "Content-Type": {
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Empty"
                }
              }
            }
          },
          "400": {
            "description": "400 response",
            "content": {}
          },
          "500": {
            "description": "500 response",
            "content": {}
          }
        },
        "security": [
          {
            "sigv4": []
          }
        ]
      }
    },
    "/": {
      "get": {
        "responses": {
          "200": {
            "description": "200 response",
            "headers": {
              "Content-Length": {
                "schema": {
                  "type": "string"
                }
              },
              "Timestamp": {
                "schema": {
                  "type": "string"
                }
              },
              "Content-Type": {
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Empty"
                }
              }
            }
          },
          "400": {
            "description": "400 response",
            "content": {}
          },
          "500": {
            "description": "500 response",
            "content": {}
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Empty": {
        "title": "Empty Schema",
        "type": "object"
      }
    },
    "securitySchemes": {
      "sigv4": {
        "type": "apiKey",
        "name": "Authorization",
        "in": "header",
        "x-amazon-apigateway-authtype": "awsSigv4"
      }
    }
  }
}
EN

回答 1

Stack Overflow用户

发布于 2021-11-19 09:45:17

如果仔细阅读文档,您将看到:

有效载荷大小限制为10 MB。有关配置和运行REST的API网关配额。

因为有效负载也是base64编码的,这意味着实际上,即使文件小于10 is,也会达到限制。

API网关不应该用于服务大文件。推荐的方法是使用API和创建预先签名的urls,并将用户重定向到那里。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70031685

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档