Skip to content

aws-samples/generate-s3-accelerate-presigned-url

Generate S3 Presigned URL with S3 Transfer Acceleration

This project demonstrates how to generate an Amazon S3 presigned URL with S3 Transfer Acceleration, using Amazon API Gateway REST API and AWS Lambda function. The Lambda function, composed in Java 21, is responsible for generating a presigned URL to allow customers to upload a single file into S3, with S3 Transfer Acceleration enabled, to speed up content transfers to Amazon S3 securely, over long distances. The API is protected by IAM authentication, to protect against non-authenticated users.

You can deploy this application with the AWS Serverless Application Model (SAM) CLI.

Prerequisites

Deployment

  1. Clone the repository:

    git clone https://github.com/aws-samples/generate-s3-accelerate-presigned-url.git
  2. Change to the project directory:

    cd generate-s3-accelerate-presigned-url
  3. Build the application:

    sam build
  4. Deploy the application:

    sam deploy --guided

    During the deployment process, you will be prompted to provide the following parameters:

    • S3BucketName: The name of the S3 bucket where the uploaded files will be stored.

    The SAM CLI will guide you through the rest of the deployment process, including creating an AWS CloudFormation stack and deploying the necessary resources.

Usage

After the deployment is complete, the SAM CLI will output the API endpoint URL. You can use this endpoint to generate a presigned URL for uploading files to the specified S3 bucket with S3 Transfer Acceleration enabled.

To generate a presigned URL, send a POST request to the /upload endpoint with the filename query parameter, like this:

POST https://<api-id>.execute-api.<region>.amazonaws.com/Prod/upload?filename=example.txt

The response will contain the presigned URL, which you can use to upload the file to S3 with Transfer Acceleration enabled.

Here's an example using curl:

curl -X POST https://<api-id>.execute-api.<region>.amazonaws.com/Prod/upload?filename=example.txt

This will return a JSON response with the presigned URL:

{
  "presignedUrl": "https://my-bucket.s3-accelerate.amazonaws.com/example.txt?....."
}

You can then use the returned presigned URL to upload the file to the specified S3 bucket.

Security

The API is protected by IAM authentication to prevent unauthorized access. Make sure to configure the necessary IAM permissions for your application to access the API and the S3 bucket.

License

This project is licensed under the MIT-0 License.

About

No description, website, or topics provided.

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages