4

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
John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
Stefan Peter
  • 341
  • 1
  • 8

1 Answers1

4

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

};
Ka Hou Ieong
  • 5,835
  • 3
  • 20
  • 21
  • The presigned S3 URL is calculated and set in the swagger file for the stage. It is created by the buildsystem which creates and deployes the swagger file. The solution via lambda I found everywhere but it is more code to be taken care of. :/ – Stefan Peter Jun 27 '17 at 09:51