DEV Community

Cover image for Keep Your AWS S3 Demo Assets Live: Automating Presigned URLs with Node.js
Dan Zeitman
Dan Zeitman

Posted on

Keep Your AWS S3 Demo Assets Live: Automating Presigned URLs with Node.js

TL;DR

You work with audio (or any media) all the time and have demo assets stored securely on Amazon S3.

You want to load these into your apps or SDK demos — but your presigned URLs keep expiring.

This CLI tool also supports uploading files or directories to your S3 demo‑assets bucket and listing bucket contents — all with one command.

This little Node.js CLI tool lets you:

  • quickly upload a media asset object to your AWS Bucket
  • generate presigned URLs for your S3 bucket (demo-assets/)
  • save them in a JSON file for easy import into any project
  • refresh them anytime with a single command

Let’s walk through how to install and use it.

npx -g create-demo-assets 
Enter fullscreen mode Exit fullscreen mode

That's it!

Open a terminal and run that cmd. Well almost, this tool is for managing AWS objects, so there is the expectation you've have the AWS CLI tool already installed and use their tool to manage your credentials. Scroll down for a deeper explanation.


Basic Use Case

On AWS 3, you might have something like:

s3://audioshake/demo-assets/
├── Chupe-Jaae-English.mp4
├── Vocal-Demo.wav
├── Guitar-Solo.mp3
Enter fullscreen mode Exit fullscreen mode

Now your local or web app can fetch demo assets reliably — and when URLs expire, just rerun create-demo-assets. These are your demo media files — used for testing APIs, web players, or internal demos.

You could manually create a presigned URL each time, but that’s tedious.

Instead, you’ll use this lightweight CLI to generate a simple demo-assets.json:

{
  "assets": [
    {
      "src": "https://audioshake.s3.us-east-1.amazonaws.com/demo-assets/Vocal-Demo.wav?...",
      "title": "Vocal-Demo.wav",
      "format": "audio/wav",
      "expiry": "2025-10-14T09:45:00.000Z"
    }
  ]
}
Enter fullscreen mode Exit fullscreen mode

Using The tool:

From any directory:

create-demo-assets
Enter fullscreen mode Exit fullscreen mode

It will:

  • list all objects in your S3 folder
  • generate presigned URLs (default 12‑hour expiry)
  • save demo-assets.json in your current working directory

🔍 Listing objects in s3://audioshake/demo-assets/ ...
demo-assets.json created with 8 assets
Enter fullscreen mode Exit fullscreen mode

Upload or List Assets

You can now upload new demo files or check what’s in your bucket without generating JSON.

Upload a single file:

create-demo-assets --upload ./song.mp3
Enter fullscreen mode Exit fullscreen mode

Upload a directory:

create-demo-assets --uploadDir ./assets --type=mp3,mp4
Enter fullscreen mode Exit fullscreen mode

List all files:

create-demo-assets --list
Enter fullscreen mode Exit fullscreen mode

If you pass --type, only matching file extensions are included. Supported formats include mp3, wav, mp4, mov, json, txt, md, and more.


How to configure the tool for AWS

Make sure you have the AWS CLI installed set up with a config profile that can read from your bucket:

aws configure --profile admin
# Region: us-east-1
# Output: json
Enter fullscreen mode Exit fullscreen mode

You can verify:

aws sts get-caller-identity --profile admin
# This will print the S3 arn:
aws s3 ls s3://<Your-AWS-Bucket>/demo-assets/ --profile admin
Enter fullscreen mode Exit fullscreen mode

Ensure your IAM policy allows s3:ListBucket and s3:GetObject for your demo‑assets prefix.

Need to update your credentials?

This cmd will install the dependencies globally and creates a config file that stores your bucket information and which AWS profile to use.

# Run setup again to change the config
create-demo-assets --setup
Enter fullscreen mode Exit fullscreen mode

How It Works (Under the Hood)

The script uses the AWS SDK v3:

import { S3Client, ListObjectsV2Command, GetObjectCommand } from "@aws-sdk/client-s3";
import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
import { fromIni } from "@aws-sdk/credential-providers";
Enter fullscreen mode Exit fullscreen mode

It lists objects, creates presigned URLs via GetObjectCommand, and writes them to JSON.

If your bucket has no LocationConstraint (the classic us‑east‑1 case), the CLI automatically signs requests for that region.

The same script now handles uploads and listing via the same S3 client — no extra configuration required.


Refreshing URLs

Each URL has a 12‑hour expiry by default.

When your links expire, just rerun:

create-demo-assets
Enter fullscreen mode Exit fullscreen mode

and it’ll overwrite the old JSON with fresh URLs.


Example Output

🔍 Listing objects in s3://audioshake/demo-assets/ ...
demo-assets.json created with 8 assets
Enter fullscreen mode Exit fullscreen mode

demo-assets.json now contains:

{
  "assets": [
    { "src": "...", "title": "Guitar-Solo.mp3", "format": "audio/mpeg", "expiry": "2025-10-14T10:00:00Z" }
  ]
}
Enter fullscreen mode Exit fullscreen mode

Open Sourced, Feel free to extend the tool!

You can fork the GitHub Repository: AWS-Demo-Assets-Tool to add new features to the tool. Finally npx distribution is here on npmjs.com. if you find the tool useful then share and drop us some ⭐️⭐️⭐️⭐️⭐️'s
Drop a comment to let me know your use case, and feel free to suggest new features.


Why It’s Useful

This simple tool bridges your secure S3 assets with live demos or dev environments — without exposing buckets or manually generating presigned URLs every time.

Recent updates make it easier to keep demo assets synchronized: you can upload, list, and regenerate presigned URLs from one CLI.

Perfect for:

  • API demos
  • Audio/Video SDK previews
  • Internal or hackathon projects

Tags: #aws #nodejs #cli #developers #audioshake

The roadmap includes additional S3 management features and examples. Stay tuned for more developer-facing utilities.


Caution: Avoid exposing your presigned JSON publicly or using overly long expirations.

Top comments (0)