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 🙏

© 2026 – Pkg Stats / Ryan Hefner

s3-lock

v1.0.1

Published

A library for acquiring and releasing distributed locks via S3.

Readme

S3-Lock

A library for acquiring and releasing distributed locks via S3.

Why?

  • Assuming no lock contention, acquiring and then releasing a lock "only" costs $0.0009 USD 💸🤑💰
  • Fast, releasing and acquiring locks "only" takes 10s of milliseconds 🏃💨💨
  • Using strange/non idiomatic patterns for locking is a good idea 🔒🔓🔑

Examples

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

const lock = await locker.acquireLock({
    bucket,
    key,
    generateBody: async () => JSON.stringify({
        locked: true
    })
});

// do work

await lock.release(JSON.stringify({ locked: false }));

Technical details

As of 2024/08/20, S3 supports distributed locking through conditional writes.

Conditional writes are done via conditional requests.

Specifically the If-Match and If-None-match headers.

If-Match
Uploads the object only if the ETag (entity tag) value provided during the WRITE operation matches the ETag of the object in S3. If the ETag values do not match, the operation returns a 412 Precondition Failed error.

If-None-Match
Uploads the object only if the object key name does not already exist in the bucket specified. Otherwise, Amazon S3 returns a 412 Precondition Failed error.

The If-Match supports acquiring and releasing locks by overwriting a lock's status to a file. An entity can assume ownership if the overwrite succeeds.

Clients can acquire a lock via writing {locked: true} to an existing file whose original value was {locked: false}. To ensure no clobbers occur the overwrite will only succeed if the ETag is the same at write time.

The If-None-match supports acquiring locks by writing a lock's status to a new file. An entity can assume ownership if the write succeeds.

Clients can acquire a lock via writing anything to a new file. To ensure no clobbers happen the write will only succeed if no file exists with such a name.

Lock expiration can be achieved via fencing tokens either via monotonically increasing values within the lock files, alternatively the time stamps of the files could be utilized.