Redirecting AWS API Gateway to S3 Binary

别说谁变了你拦得住时间么 提交于 2020-05-15 04:29:08

问题


I'm trying to download large binaries from S3 via an API Gateway URL. Because the maximum download size in API Gateway is limited I thought I just could provide the basic URL to Amazon S3 (in the swagger file) and add the folder/item to the binary I want to download.

But all I find is redirection API Gateway via a Lambda function, but I don't want that.

I want a swagger file where the redirect is already configured.

So if I call <api_url>/folder/item I want to be redirected to s3-url/folder/item

Is this possible? And if so, how?

Example:

  • S3: https://s3.eu-central-1.amazonaws.com/folder/item (item = large binary file)
  • API Gateway: https://<id>.execute-api.eu-central-1.amazonaws.com/stage/folder/item -> redirect to s3 url

回答1:


I am not sure if you can redirect the request to a presigned S3 url via API Gateway without a backend to calculate the presigned S3 url. The presigned S3 url feature is provided by the SDK instead of an API. You need to use a Lambda function to calculate the presigned S3 url and return.

var AWS = require('aws-sdk');
AWS.config.region = "us-east-1";
var s3 = new AWS.S3({signatureVersion: 'v4'});
var BUCKET_NAME = 'my-bucket-name'

exports.handler = (event, context, callback) => {

    var params = {Bucket: BUCKET_NAME, Key: event.path};
    s3.getSignedUrl('putObject', params, function (err, url) {
        console.log('The URL is', url);
        callback(null, url);
    });

};


来源:https://stackoverflow.com/questions/44756517/redirecting-aws-api-gateway-to-s3-binary

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!