npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

aws-s3-presigned-url-generator

v1.0.4

Published

This package provides utility functions to generate presigned URLs for uploading, retrieving, and listing objects in an AWS S3 bucket. Using AWS SDK for JavaScript (`@aws-sdk/client-s3`), it allows you to perform the following actions:

Downloads

18

Readme

S3 Presigned URL Utility

This package provides utility functions to generate presigned URLs for uploading, retrieving, and listing objects in an AWS S3 bucket. Using AWS SDK for JavaScript (@aws-sdk/client-s3), it allows you to perform the following actions:

  • Upload objects to S3 using a presigned URL.
  • Retrieve objects from S3 using a presigned URL.
  • List objects in a bucket using a presigned URL.

Features

  • Generate presigned URL for uploading files to S3.
  • Generate presigned URL for downloading files from S3.
  • Generate presigned URL to list objects in a specific S3 path.
  • Specify expiration time for presigned URLs (defaults to 24 hours).

Installation

Before using the utility, ensure you have installed the necessary dependencies:

npm install @aws-sdk/client-s3 @aws-sdk/s3-request-presigner

Usage

1. Generate a Presigned URL for Uploading an Object

import { createPresignedUrlWithClient } from './path/to/utility';
import { S3Client } from '@aws-sdk/client-s3';

const s3Client = new S3Client({ region: 'us-east-1' });

const uploadUrl = await createPresignedUrlWithClient({
  s3Client,
  bucket: 'my-bucket',
  key: 'uploads/myfile.png',
  expiresIn: 3600, // URL valid for 1 hour
  contentType: 'image/png'
});

2. Generate a Presigned URL for Downloading an Object

import { createSignedUrlForGetObject } from './path/to/utility';
import { S3Client } from '@aws-sdk/client-s3';

const s3Client = new S3Client({ region: 'us-east-1' });

const downloadUrl = await createSignedUrlForGetObject({
  s3Client,
  bucket: 'my-bucket',
  key: 'uploads/myfile.png',
  expiresIn: 3600 // URL valid for 1 hour
});

3. Generate a Presigned URL for Listing Objects in a Path

import { getBatchPresignedUrlsWithClient } from './path/to/utility';
import { S3Client } from '@aws-sdk/client-s3';

const s3Client = new S3Client({ region: 'us-east-1' });

const listUrl = await getBatchPresignedUrlsWithClient({
  s3Client,
  bucket: 'my-bucket',
  pathPrefix: 'uploads/',
  expiresIn: 3600 // URL valid for 1 hour
});

API Reference

createPresignedUrlWithClient(options)

Generates a presigned URL for uploading an object to an S3 bucket.

  • Parameters:

    • s3Client (required): An instance of S3Client from @aws-sdk/client-s3.
    • bucket (required): The name of the S3 bucket.
    • key (required): The object key (e.g., myfolder/myfile.png).
    • expiresIn (optional): Expiration time for the presigned URL in seconds (default is 24 hours).
  • Returns: A promise that resolves to the presigned URL.

createSignedUrlForGetObject(options)

Generates a presigned URL for downloading an object from an S3 bucket.

  • Parameters:

    • s3Client (required): An instance of S3Client from @aws-sdk/client-s3.
    • bucket (required): The name of the S3 bucket.
    • key (required): The object key (e.g., myfolder/myfile.png).
    • expiresIn (optional): Expiration time for the presigned URL in seconds (default is 24 hours).
  • Returns: A promise that resolves to the presigned URL.

getBatchPresignedUrlsWithClient(options)

Generates a presigned URL for listing objects in an S3 bucket.

  • Parameters:

    • s3Client (required): An instance of S3Client from @aws-sdk/client-s3.
    • bucket (required): The name of the S3 bucket.
    • pathPrefix (optional): The prefix for listing objects (e.g., uploads/).
    • expiresIn (optional): Expiration time for the presigned URL in seconds (default is 24 hours).
  • Returns: A promise that resolves to the presigned URL.

Types

ICreatePresignedUrlWithClientBody

Defines the shape of the request body for generating presigned URLs for upload and download.

interface ICreatePresignedUrlWithClientBody {
  s3Client: S3Client;
  bucket: string;
  key: string;
  expiresIn?: number;
}

IGetBatchPresignedUrlWithClientBody

Defines the shape of the request body for generating presigned URLs for listing objects in a bucket.

interface IGetBatchPresignedUrlWithClientBody extends ICreatePresignedUrlWithClientBody {
  pathPrefix?: string;
}

License