将AWS API Gateway重定向到S3 Binary [英] Redirecting AWS API Gateway to S3 Binary
问题描述
我正在尝试通过API网关URL从S3下载大型二进制文件.由于API网关中的最大下载大小受到限制,我想我可以提供Amazon S3的基本URL(在swagger文件中)并将文件夹/项目添加到我要下载的二进制文件中.
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.
但是我发现的只是通过Lambda函数重定向API网关,但是我不想要那样.
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.
因此,如果我拨打<api_url>/folder/item
,我想重定向到s3-url/folder/item
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?
示例:
- S3:
https://s3.eu-central-1.amazonaws.com/folder/item
(项目=大的二进制文件) - API网关:
https://<id>.execute-api.eu-central-1.amazonaws.com/stage/folder/item
->重定向到s3网址
- 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
推荐答案
我不确定您是否可以通过API网关将请求重定向到预先签名的S3 url,而无需后端来计算预先签名的S3 url. SDK提供了预先签名的S3 url功能,而不是API.您需要使用Lambda函数来计算预设的S3网址并返回.
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);
});
};
这篇关于将AWS API Gateway重定向到S3 Binary的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!