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

Messages with "payload" property broken in spring-cloud-function-adapter-aws #1154

Open
M0rious opened this issue Jun 24, 2024 · 5 comments
Open
Assignees
Milestone

Comments

@M0rious
Copy link

M0rious commented Jun 24, 2024

Describe the bug
We are using SpringCloudFunctions on AWS for Lambdas.
The messages send to the Lambdas contain a property "payload".
This worked fine up until spring-cloud-function-adapter-aws@4.0.6.
With the current version 4.1.2 the message does not reach the lambda implementation correctly.
Only the "payload" property gets passed to the function-code

Sample
Deploy a SCF-Lambda to AWS or Localstack and log the input:

@SpringBootApplication
@Slf4j
public class SampleLambda {

  @Bean
  public Function<Message<String>, String> transformMessage() {
    return input -> {
        log.info("Debug: {}", input.getPayload());
      return input.getPayload();
    };
  }
}

Sample-Input:

{
  "a": "b",
  "payload": {
    "c": "d"
  }
} 

Output:

"Debug: {\"c\":\"d\"},.."

@olegz olegz self-assigned this Jun 24, 2024
@olegz olegz added the AWS label Jun 24, 2024
@olegz olegz added this to the 4.1.3 milestone Jun 24, 2024
@olegz
Copy link
Contributor

olegz commented Jun 24, 2024

Since this message does not correspond to any valid format we really don't know what "a": "b", is. Wouldn't it be better if you incorporate it under headers

"headers": {"a":"b"}

We monitor that?

@M0rious
Copy link
Author

M0rious commented Jun 24, 2024

The lambda is triggered by a step function that builds a json object as input for the lambda.
Why would we pass this as a header to the lambda?
Here an extended example:

{
  "someProperty": "someValue",
  "payload": {
    "otherProperty": "otherValue"
  }
} 

Would log:
"Debug: {\"otherProperty\":\"otherValue\"},.."
Everything outside of the "payload" property of the message we build for the lambda does not reach our code.

@mrjv
Copy link

mrjv commented Jun 26, 2024

We are getting a similar error after upgrading to Spring Cloud Function 4.1.1. (Or actually same as #1135, but after upgrading to 4.1.2 I expect the same as above). Same scenario as @M0rious: our Lambda input request has a json field called "payload" that is not expecting any special handling on an AWS Lambda adapter level.

The special handling of the "payload" field seems to have been introduced by the following commit, although I'm not sure how the change is related to #1086 as mentioned in the commit message:
8a93e10#diff-c3541839d4b70d7bf7b3c116f62949cdab0fd8923e1ccf57a6788e6411d67d87

@olegz What was the original reason for adding special handling of requests having a "payload" field? Ideally there would be some way to opt in or opt out from this behavior to avoid breaking changes to existing AWS Lambda functions.

@olegz
Copy link
Contributor

olegz commented Jul 3, 2024

Don't get me wrong, we can fix it, just trying to understand your expectation and what I read is that given that Spring Message has a distinct payload field, you would expect/like your payload to go there and the rest as headers, correct?

@M0rious
Copy link
Author

M0rious commented Jul 5, 2024

Don't get me wrong, we can fix it, just trying to understand your expectation and what I read is that given that Spring Message has a distinct payload field, you would expect/like your payload to go there and the rest as headers, correct?

Yes - if we send a JSON-Message to the Lambda we expect the whole message to be in the payload field - regardless of the fields contained in the message we send.

We use Message as Input for the Lambda so we can call getHeaders to use e.g. the 'aws-context' header for logging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants