Skip to content

(custom-resources): Provider function is throwing "Error: return values from user-handlers must be JSON objects. got: "" #26429

@mrlikl

Description

@mrlikl

Describe the bug

Hello team,

I am seeing the error Error: return values from user-handlers must be JSON objects. got: "" recently while using the Provider construct of aws-cdk-lib/custom-resources. Checking the cloudwatch logs of the request, I see that this is the return value sent back from the oneventhandler lambda fn.

{
    $metadata: {
      httpStatusCode: 200,
      requestId: 'xxxx',
      attempts: 1,
      totalRetryDelay: 0
    },
    ExecutedVersion: '$LATEST',
    Payload: {},
    StatusCode: 200
  }

I see that there was a change recently in parseJsonPayload function from const text = payload.toString(); to let text = new TextDecoder().decode(Buffer.from(payload));.

Expected Behavior

Provider fn to return empty values/success

Current Behavior

Provider function is throwing "Error: return values from user-handlers must be JSON objects. got: ""

Reproduction Steps

Not sure of the reproduction steps here. Although I do not see any return from the event lambda.
This works fine if the return logged is "" like

{
    $metadata: {
      httpStatusCode: 200,
      requestId: 'xxxx',
      attempts: 1,
      totalRetryDelay: 0
    },
    ExecutedVersion: '$LATEST',
    Payload: "",
    StatusCode: 200
  }

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.87.0

Framework Version

No response

Node.js Version

18.16

OS

mac

Language

Typescript

Language Version

No response

Other information

No response

Metadata

Metadata

Assignees

Labels

@aws-cdk/custom-resourcesRelated to AWS CDK Custom ResourcesbugThis issue is a bug.effort/smallSmall work item – less than a day of effortnode18-upgradeAny work (bug, feature) related to Node 18 upgradep1

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions