带有子目录的 S3 API 网关代理 [英] API Gateway Proxy for S3 with subdirectories

查看:18
本文介绍了带有子目录的 S3 API 网关代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为S3"创建了一个集成类型为AWS 服务"的 API 网关方法 GET.我定义了一个路径覆盖:从 method.request.path.item

映射的 {object}

只要路径只包含存储桶本身(./bucket/mybucketname),它就可以工作,{item} 的值为 mybucketname.

但是当我指定例如 ../bucket/mybucketname/foo/bar/test.txt 作为路径时,{item} 值应该是 mybucketname/foo/bar/test.txt 但它.我认为这是因为嵌套路径

当我选择全部路径变量 {proxy+} 时,我无法再选择集成类型AWS 服务".

任何提示我做错了什么或我应该做什么才能通过 API Gateway 从 S3 检索子文件夹中的文件/文件夹?

解决方案

这可以使用

集成响应:

方法响应:

I created an API Gateway method GET with integration type "AWS Service" for "S3". I defined a Path override: {object} that is mapped from method.request.path.item

As long as the path contains only the bucket itself (./bucket/mybucketname), it works and the value of {item} is mybucketname.

But when i specify for example ../bucket/mybucketname/foo/bar/test.txt as path the {item} value should be mybucketname/foo/bar/test.txt but it is empty. I think it's because of the nested path

When i choose catch-all path variables {proxy+} I'm not able to choose integration type "AWS Service" any longer.

Any hints what I'm doing wrong or what i should do in order to retrieve files/folders in subfolders from S3 via API Gateway?

解决方案

This can be done using proxy resource.

Here are my steps to achieve what @Johnny90 wants:

  1. Click on your API in the API Gateway console.

  2. Choose the /bucket resource and then choose Create Resource from the Actions drop-down menu. Then, do the following in the New Child Resource pane.

    a. Tick "Configure as proxy resource".

    b. Use the default proxy for Resource Name.

    c. Use {proxy+} for Resource Path.

    d. Choose Create Resource.

  3. Choose HTTP Proxy for Integration type and type the Endpoint URL as any website (e.g., https://my-website.com/{proxy} ). Then choose Save.

  4. Choose Integration Request

    a. Select AWS Service as the Integration type.

    b. From the AWS Region drop-down list, choose the region that your S3 bucket resides in.

    c. From AWS Service, choose S3. For AWS Subdomain, leave it blank.

    d. For HTTP method, choose GET.

    e. Choose Use path override for Action Type. and type bucket/{proxy}.

    f. Paste an IAM role that has enough permissions.

    g. Click Save.

After changing the integration request from HTTP Proxy integration to AWS Service, we have to add some settings for the API. First, you must set up the URL Path Parameters so that API Gateway can understand the {proxy} variable defined in resource path in Integration Request.

  1. Extend URL Path Parameters in Integration Request and then choose Add path.

  2. Type proxy in the Name column and method.request.path.proxy in the Mapped from column.

Second, choose Method Response from Method Execution.

  1. Choose Add Response. Type 200 for HTTP status.

  2. Expand the response of the 200 code.

    a. Choose Add Header. Type Content-Type for the Name.

    b. Click Add Response Model. Type application/json for Content type and choose Empty from the Models drop-down menu.

Finally, choose Integration Response from Method Execution.

  1. Extend the 200 Method response status

  2. For Header Mapping, you should see the Content-Type in the Response header column. Type integration.response.header.Content-Type in the Mapping value column.

The following are my configurations:

Integration Request:

Integration Response:

Method Response:

这篇关于带有子目录的 S3 API 网关代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆