Skip to content

bb-kv-store: an expired item is gone locally after get(), but still blocks put({ ifNotExists }) and shows up in scan({ includeExpired }) on AWS #1275

Closed

Description

@belaboe

Before opening, please confirm

  • I have searched for duplicate or closed issues.
  • I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.

Which package(s) are affected?

Building Block: kv-store

Describe the bug

DynamoDB's TTL deletes expired items in the background, typically within a few days; until then they still exist for reads, conditional writes and scans. The block hides them from get() and scan() in both environments, but the local mock also deletes an expired item as soon as get() sees it, and the AWS path doesn't treat expired items as absent in its conditions. After put(key, v, { expiresAt: <past> }) and a get(key) that returns null:

Next call Local Deployed
put(key, 'fresh', { ifNotExists: true }) ok ConditionalCheckFailedException (409)
delete(key, { ifExists: true }) ConditionalCheckFailedException (409) ok
scan({ includeExpired: true }) item not yielded item yielded

So the common "create if absent" pattern (for example a lock or an idempotency key with a TTL) works locally and fails on AWS for as long as the expired item lingers, even though get() reports the key as absent in both environments.

Expected behavior

get(), conditional writes and scan() agree about expired items in both environments. Probably:

  • AWS: ifNotExists uses attribute_not_exists(pk) OR <ttl> < :now and ifExists uses attribute_exists(pk) AND <ttl> >= :now (or the absence of the TTL attribute), so an expired item counts as absent, matching get().
  • Mock: get() filters expired items without deleting them, so scan({ includeExpired: true }) still yields them until the reaper runs, as on AWS.

Reproduction steps

const store = new KVStore<string>(scope, 'locks', {});
const past = new Date(Date.now() - 60_000);

await store.put('job-42', 'old', { expiresAt: past });
await store.get('job-42');                                 // null in both
await store.put('job-42', 'fresh', { ifNotExists: true }); // ok locally, ConditionalCheckFailedException deployed

Environment

  • @aws-blocks/* 0.8.0 (main at 34e758c)
  • Local: npm run dev dev server, Node 22, macOS
  • Deployed: a sandbox stack in us-east-1

Additional context

  • https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ttl-expired-items.html (expired items appear in read and write operations until they are deleted; filter them with a condition on the TTL attribute).
  • Likely location: get() in packages/bb-kv-store/src/index.mock.ts (lines 141–150 delete the entry when it is expired); the conditions in put() / delete() in packages/bb-kv-store/src/index.aws.ts (around lines 114–115 and 197–198).

Activity

  1. sharonyajain commented on Nov 18, 2026

    @sharonyajain
    Contributor

    Thanks for the detailed report. Closing this one.

    Local store: fixed on main by #1453. The mock no longer deletes an expired item when get() reads it.

  2. self-assigned this
    on Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions