Skip to content

bb-async-job: the local handler receives the caller's payload object itself, on AWS it receives a JSON copy (mutations, Date, Map, Set, Buffer and class instances differ) #1276

Open

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: async-job, Building Block: cron-job

Describe the bug

On AWS, submit(payload) sends JSON.stringify(payload) to SQS and the handler gets JSON.parse() of it. The local mock measures the JSON size but then queues the original object and passes it to the handler on the next tick. So the handler sees whatever the caller does to the object after submit() resolves, and every value JSON can't represent arrives intact:

Payload field Handler sees locally Handler sees on AWS
a field the caller changes right after await submit(payload) the changed value the value at submit time
new Date(…) a Date an ISO string
new Map() / new Set() Map / Set {}
{ a: undefined } key a present key absent
NaN, Infinity, an array hole NaN, Infinity, undefined null
-0 -0 0
Buffer / Uint8Array Buffer / Uint8Array { type: 'Buffer', data: [...] } / { "0": …, "1": … }
an object with toJSON() the object the toJSON() result
a class instance the instance, methods callable a plain object, no methods

A handler written as payload.createdAt.getTime() or payload.ids.has(x) works in npm run dev and throws on AWS. CronJob has the same pattern for its input: a Date in input reaches the local handler as a Date and the deployed one as a string.

Expected behavior

The mock passes the handler JSON.parse(JSON.stringify(payload)) (it already computes the string for the size check), taken at submit() time, for submit(), submitBatch() and CronJob's input. The README can then state that payloads are JSON-serialized in both environments.

Reproduction steps

const job = new AsyncJob(scope, 'ingest', {
  handler: async (payload: { mark: string; at: Date; ids: Set<string> }) => {
    console.log(payload.mark, typeof payload.at, payload.ids instanceof Set);
  },
});

const payload = { mark: 'at-submit', at: new Date(), ids: new Set(['a']) };
await job.submit(payload);
payload.mark = 'changed-after-submit';
// local:    "changed-after-submit object true"
// deployed: "at-submit string false"

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

Activity

  1. added
    pending-triage
    pending-maintainer-response
    on Nov 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    pending-maintainer-responsepending-triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions