TLTan LeBackend & automation · CalgaryLet’s talk
← All posts

Uploading to S3 through an API Gateway service proxy, with subdirectories

Step-by-step notes for an API Gateway service proxy that reads and writes S3 objects in nested folders through a single {proxy+} resource.

From the archive · a 2021 working note, kept for reference.

This is a guide to creating the AWS API Gateway.

Assumption: the S3 bucket is named us-east-1-dev, with folders light/ → test_1/ → pdfs/.

Create the REST API

  1. Create a proxy resource.
  2. Select the service proxy:
    • Resource Name: proxy
    • Resource Path: {proxy+}
  3. Click Create API.
  4. Select the option HTTP proxy.
    • Endpoint URL: anything, e.g. https://testing.com/{proxy}
  5. Click Save.

Integration Request

  1. Integration type: AWS service.
  2. Select the desired region.
  3. Select the desired AWS service (S3 in my case).
  4. In subdomain, give the bucket name (e.g. xxxx-us-east-1-dev).
  5. HTTP method: select PUT if you want to upload an object, GET if you want to get it. Here it is PUT.
  6. In path override, give {proxy} (to pass the bucket name dynamically).
  7. Finally, the API Gateway service proxy needs a role ARN. For a detailed explanation of creating it, follow the documentation.

Method Response

HTTP Status: fill in 200.

Integration Response

Fill in integration.response.header.Content-Type as the mapping value, then Save.

Test

Select the method you chose above. For the path, key in the file you want to get, e.g. light/test_2/pdfs/dummy.txt.

First published on tanldt.blogspot.com on May 26, 2021.