Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
mrlikl opened this issue Jul 19, 2023 · 6 comments · Fixed by #27000
Assignees
Labels
@aws-cdk/custom-resources Related to AWS CDK Custom Resources bug This issue is a bug. effort/small Small work item – less than a day of effort node18-upgrade Any work (bug, feature) related to Node 18 upgrade p1

Comments

@mrlikl
Copy link
Contributor

mrlikl commented Jul 19, 2023

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

@mrlikl mrlikl added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jul 19, 2023
@github-actions github-actions bot added the @aws-cdk/custom-resources Related to AWS CDK Custom Resources label Jul 19, 2023
@peterwoodworth
Copy link
Contributor

Logging the return as "" probably works because that is a falsy value, as opposed to {}. Looks like this was an edge case that went unaccounted for. Does this break you and prevent you from being able to properly upgrade without making changes @mrlikl?

@peterwoodworth peterwoodworth added p1 effort/small Small work item – less than a day of effort needs-review and removed needs-triage This issue or PR still needs to be triaged. labels Jul 19, 2023
@mrlikl
Copy link
Contributor Author

mrlikl commented Jul 21, 2023

I do not have direct access to the onevent lambda code. The payload data is from the provider lambda's logs.

@jalvinake
Copy link

I am also having this exact error. I am unable to upgrade our production system due to it.

@mrgrain mrgrain assigned MrArnoldPalmer and unassigned mrgrain Aug 22, 2023
@MrArnoldPalmer
Copy link
Contributor

@jalvinake @mrlikl can you provide an example of what your handler is returning (I know you said you don't have access to the handler code is it a CR in aws-cdk-lib?)? I'm pretty sure we can just change the logic to something similar to the change we made in AwsCustomResource, but I want to make sure I have a good test here.

@rtfinspace
Copy link

rtfinspace commented Aug 24, 2023

we recently migrated to cdkv2, Provider lambda errored with this return response object .
{
$metadata: {
httpStatusCode: 200,
requestId: 'xxxx',
attempts: 1,
totalRetryDelay: 0
},
ExecutedVersion: '$LATEST',
Payload: {},
StatusCode: 200
}

Provider lambda used nodejs18 as runtime. Having issues specifically with this.
There are other packages with exact same implementation, where Provider lambda doesnt have any issues, uses nodejs14 as runtime. Not sure if the error is because of nodejs18 ?

@udaypant udaypant added the node18-upgrade Any work (bug, feature) related to Node 18 upgrade label Aug 31, 2023
@rix0rrr rix0rrr self-assigned this Sep 4, 2023
rix0rrr added a commit that referenced this issue Sep 4, 2023
The payload response of a Lambda used to be a `string`, and could
occasionally be `""`, which we detected and special-case parsed to
an empty object.

In SDKv3, the payload response of a Lambda changed to type `Uint8Array`,
but a `Uint8Array(0)` doesn't check as *falsey*, so we'd decode it to
`""` and then the `JSON.parse()` of that would fail.

First decode, then check the string for emptyness.

Fixes #26429.
rix0rrr added a commit that referenced this issue Sep 6, 2023
…t failure (#27000)

The payload response of a Lambda used to be a `string`, and could occasionally be `""`, which we detected and special-case parsed to an empty object. The Payload should never be empty, and will only be that under exceptional circumstances which we haven't been able to pin down yet, but we shouldn't fail in any case.

In SDKv3, the payload response of a Lambda changed to type `Uint8Array`, but a `Uint8Array(0)` doesn't check as *falsey*, so we'd decode it to `""` and then the `JSON.parse()` of that would fail.

First decode, then check the string for emptyness.

Fixes #26429.
@github-actions
Copy link

github-actions bot commented Sep 6, 2023

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

mikewrighton pushed a commit that referenced this issue Sep 14, 2023
…t failure (#27000)

The payload response of a Lambda used to be a `string`, and could occasionally be `""`, which we detected and special-case parsed to an empty object. The Payload should never be empty, and will only be that under exceptional circumstances which we haven't been able to pin down yet, but we shouldn't fail in any case.

In SDKv3, the payload response of a Lambda changed to type `Uint8Array`, but a `Uint8Array(0)` doesn't check as *falsey*, so we'd decode it to `""` and then the `JSON.parse()` of that would fail.

First decode, then check the string for emptyness.

Fixes #26429.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/custom-resources Related to AWS CDK Custom Resources bug This issue is a bug. effort/small Small work item – less than a day of effort node18-upgrade Any work (bug, feature) related to Node 18 upgrade p1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants