Stefan Peter
Stefan Peter

Reputation: 361

Redirecting AWS API Gateway to S3 Binary

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:

Upvotes: 4

Views: 1164

Answers (1)

Ka Hou Ieong
Ka Hou Ieong

Reputation: 6535

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);
    });

};

Upvotes: 4

Related Questions