-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
fix(custom-resources): empty Lambda response payload causes deployment failure #27000
Conversation
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.
A comment requesting an exemption should contain the text Exemption Request
. Additionally, if clarification is needed add Clarification Request
to a comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a test is warranted...if not an integ that at least a unit test. though i suspect integ would actually be easier to write :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same issue will be present here, and we probably should align on a single implementation for this.
aws-cdk/packages/@aws-cdk/integ-tests-alpha/lib/assertions/providers/lambda-handler/utils.ts
Line 1 in 5d497f9
export function parseJsonPayload(payload: any): any { |
In fact I don't know how to trigger the empty Payload response condition. It seems to be an unusual case |
} catch { | ||
return payload; | ||
throw new Error(`return values from user-handlers must be JSON objects. got: "${text}"`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can a Lambda Handler not return plain text? Or is it always converted to a JSON parsable string, i.e. "foobar"
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks to be always a JSON representation of a JavaScript object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I.e. a plain text is returned as "Hi I'm a plain string"
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still concerned we are going to fail on valid values or return unexpected values.
In the assertion handler parseJsonPayload
is naively called on a potentially existing payload
property of the response object. That's different than the provider framework where we know we are dealing with a lambda response.
In hindsight, maybe we should do the assertions handler on a different PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that the code is making too many assumptions, and might be subtly broken.
I would posit that it is subtly broken already, and that nothing we're doing is making it worse than what it currently is.
But sure, I'll revert!
✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
…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.
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 aUint8Array(0)
doesn't check as falsey, so we'd decode it to""
and then theJSON.parse()
of that would fail.First decode, then check the string for emptyness.
Fixes #26429.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license