Skip to content

S3 presigned url custom domain name

0

Hi all,

I have a VPC with an ALB in it which is listening to HTTPS on a custom domain name. Behind this, I have an API Gateway and an EC2 instance. These both talk to services in a private subnet and also to S3 via a VPC endpoint (gateway).

I would like to upload files to S3 from a client through this ALB, either using multi part upload, or by presigned URL to a VPC endpoint. I want the URL to look the same as the CNAME of the ALB.

Is there a way to do this, using the ALB domain name?

I have tried using API Gateway with multipart uploads but I am hitting the 6MiB limit in lambda due to API Gateway encoding the binary in the body of the HTTP request as base64.

Thank you, Darbio

1 Answer
3

Yes, it is possible to upload files to S3 through your Application Load Balancer (ALB) using a custom domain name that matches the ALB's CNAME. This can be achieved by combining presigned URLs with your existing architecture. Here's how you can approach this:

  1. Generate presigned URLs for S3 uploads using a Lambda function behind your API Gateway. When generating these URLs, use the domain name of your ALB instead of the public S3 domain.

  2. Configure your ALB to route requests. Set up rules to send API requests to the API Gateway for generating presigned URLs, and configure a default route to send traffic intended for S3 towards the VPC endpoint for S3.

  3. Ensure that your S3 bucket has the same name as the domain you're using. This is important for the VPC endpoint to correctly route the presigned URL requests.

  4. When a client receives the presigned URL (which will contain your ALB's domain), they can use it to upload files directly through the ALB. The ALB will then route this traffic to the S3 VPC endpoint.

This setup allows you to maintain your desired URL structure while leveraging the power of presigned URLs for S3 uploads. It avoids the 6MiB Lambda limit you encountered with multipart uploads through API Gateway.

Keep in mind that you'll need to properly secure your presigned URLs, as they grant temporary access to perform specific S3 actions. Also, ensure that your VPC endpoint for S3 is correctly configured to allow the necessary actions.

This solution provides a secure way to upload files to S3 through your private network without internet traversal, enhancing security for sensitive data transfers.
Sources
Set up private access to an Amazon S3 bucket through a VPC endpoint - AWS Prescriptive Guidance
Custom domain names for HTTP APIs in API Gateway - Amazon API Gateway
Generating a presigned URL to upload an object to an S3 on Outposts bucket - Amazon S3 on Outposts

answered 2 years ago

EXPERT

reviewed 2 years ago

  • Ensure that your S3 bucket has the same name as the domain you're using. This is important for the VPC endpoint to correctly route the presigned URL requests.

    Does this mean, for example, if the custom CNAME is “uploads.domain.com”, the bucket will need to be called “uploads.domain.com”?

    Is there a way for to change this behaviour to use a different bucket name?

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.