Skip to content

4.0.6 > 4.1.0 broke the JSON parsing of lambda functions invoked via Stonebranch Lambda plugin #1135

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

Closed
srunnoe opened this issue Apr 12, 2024 · 5 comments
Assignees
Milestone

Comments

@srunnoe
Copy link

srunnoe commented Apr 12, 2024

The following commit

8a93e10#diff-c3541839d4b70d7bf7b3c116f62949cdab0fd8923e1ccf57a6788e6411d67d87

added

	MessageBuilder builder = MessageBuilder.withPayload(structMessage instanceof Map msg && msg.containsKey("payload") 
			? ((String) msg.get("payload")).getBytes(StandardCharsets.UTF_8) 
					: payload);

To the org/springframework/cloud/function/adapter/aws/AWSLambdaUtils.java class.

Which breaks when the https://stonebranchdocs.atlassian.net/wiki/spaces/UE/pages/6062516/AWS+Lambda plugin sends the following JSON payload to the lambda. The plugin allows you to send any text string you like within the payload section.

{
    "payload": {
        "headers": {
            "businessUnit": "1"
        }
    },
    "headers": {
        "aws-context": {
            "memoryLimit": 1024,
            "awsRequestId": "87a211bf-540f-4f9f-a218-d096a0099999",
            "functionName": "myfunction",
            "functionVersion": "278",
            "invokedFunctionArn": "arn:aws:lambda:us-east-1:xxxxxxx:function:xxxxx:snapstart",
            "deadlineTimeInMs": 1712717704761,
            "logger": {
                "logFiltering": {
                    "minimumLogLevel": "UNDEFINED"
                },
                "logFormatter": {},
                "logFormat": "TEXT"
            }
        },
        "businessUnit": "1",
        "id": "xxxx",
        "aws-event": true,
        "timestamp": 1712716805129
    }
}

When I upgraded to the 4.1.0 instance from the previous 4.0.6 it broke the invocation of the lambda. Please explain why the new payload section of code was added and remove if not needed.

@olegz
Copy link
Contributor

olegz commented Apr 25, 2024

I don't know what you are actually asking. What does "broke" means in your case?
There is no stack trace and no reproducible sample

@srunnoe
Copy link
Author

srunnoe commented Apr 25, 2024

The JSON is in the stack trace. This worked on version 4.0.6


`.   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v3.1.2)

2024-04-25T10:45:54.207-05:00  INFO 27452 --- [           main] c.l.cloud.simulator.StartAwsRuntime      : Starting StartAwsRuntime using Java 17.0.4 with PID 27452 (C:\xxxx\xxxxx\xxxxxx\target\classes started by xxxxx in C:\xxxxx\xxxx\xxxx)
2024-04-25T10:45:54.208-05:00 DEBUG 27452 --- [           main] c.l.cloud.simulator.StartAwsRuntime      : Running with Spring Boot v3.1.2, Spring v6.0.11
2024-04-25T10:45:54.208-05:00  INFO 27452 --- [           main] c.l.cloud.simulator.StartAwsRuntime      : The following 1 profile is active: "c8-local"
2024-04-25T10:45:55.700-05:00  INFO 27452 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [name: default]
2024-04-25T10:45:55.745-05:00  INFO 27452 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate ORM core version 6.2.6.Final
2024-04-25T10:45:55.747-05:00  INFO 27452 --- [           main] org.hibernate.cfg.Environment            : HHH000406: Using bytecode reflection optimizer
2024-04-25T10:45:56.073-05:00  INFO 27452 --- [           main] o.h.b.i.BytecodeProviderInitiator        : HHH000021: Bytecode provider name : bytebuddy
2024-04-25T10:45:56.504-05:00  INFO 27452 --- [           main] o.h.b.i.BytecodeProviderInitiator        : HHH000021: Bytecode provider name : bytebuddy
2024-04-25T10:45:56.562-05:00  WARN 27452 --- [           main] org.hibernate.mapping.RootClass          : HHH000038: Composite-id class does not override equals(): com.landsend.repositories.c8.dao.enumList.EnumListKey
2024-04-25T10:45:56.562-05:00  WARN 27452 --- [           main] org.hibernate.mapping.RootClass          : HHH000039: Composite-id class does not override hashCode(): com.landsend.repositories.c8.dao.enumList.EnumListKey
2024-04-25T10:45:57.411-05:00  INFO 27452 --- [           main] o.h.e.t.j.p.i.JtaPlatformInitiator       : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2024-04-25T10:45:57.426-05:00  INFO 27452 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [name: default]
2024-04-25T10:45:57.561-05:00  INFO 27452 --- [           main] o.h.b.i.BytecodeProviderInitiator        : HHH000021: Bytecode provider name : bytebuddy
2024-04-25T10:45:57.581-05:00  INFO 27452 --- [           main] o.h.b.i.BytecodeProviderInitiator        : HHH000021: Bytecode provider name : bytebuddy
2024-04-25T10:45:57.583-05:00  WARN 27452 --- [           main] org.hibernate.mapping.RootClass          : HHH000038: Composite-id class does not override equals(): com.xxxx.repositories.rms.dao.MerchandiseSubClassEntityKey
2024-04-25T10:45:57.583-05:00  WARN 27452 --- [           main] org.hibernate.mapping.RootClass          : HHH000039: Composite-id class does not override hashCode(): com.xxx.repositories.rms.dao.MerchandiseSubClassEntityKey
2024-04-25T10:45:57.584-05:00  WARN 27452 --- [           main] org.hibernate.mapping.RootClass          : HHH000038: Composite-id class does not override equals(): com.xxxx.repositories.rms.dao.RmsItemSupplierEntityKey
2024-04-25T10:45:57.584-05:00  WARN 27452 --- [           main] org.hibernate.mapping.RootClass          : HHH000039: Composite-id class does not override hashCode(): com.xxxx.repositories.rms.dao.RmsItemSupplierEntityKey
2024-04-25T10:45:57.584-05:00  WARN 27452 --- [           main] org.hibernate.mapping.RootClass          : HHH000038: Composite-id class does not override equals(): com.xxxx.repositories.rms.dao.UdaLovEntityKey
2024-04-25T10:45:57.584-05:00  WARN 27452 --- [           main] org.hibernate.mapping.RootClass          : HHH000039: Composite-id class does not override hashCode(): com.xxxxx.repositories.rms.dao.UdaLovEntityKey
2024-04-25T10:45:57.612-05:00  INFO 27452 --- [           main] o.h.e.t.j.p.i.JtaPlatformInitiator       : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2024-04-25T10:45:58.751-05:00  INFO 27452 --- [           main] com.xxxx.delegate.soa.SoaDelegate    : SOA URL domain was set to: http://localhost:8080/
2024-04-25T10:45:59.699-05:00  INFO 27452 --- [           main] s.a.p.PayloadStorageConfiguration        : Payload support enabled.
2024-04-25T10:46:00.379-05:00  INFO 27452 --- [           main] c.l.cloud.simulator.StartAwsRuntime      : Started StartAwsRuntime in 6.541 seconds (process running for 7.317)
2024-04-25T10:46:00.393-05:00  INFO 27452 --- [           main] o.s.c.f.adapter.aws.AWSLambdaUtils       : Received: {
    "payload": {"id": 1024},
    "headers": {
        "aws-context": {
            "memoryLimit": 1024,
            "awsRequestId": "xxxxxxx",
            "functionName": "c8Integrations-prod-HealthRmsDb",
            "functionVersion": "23",
            "invokedFunctionArn": "arn:aws:lambda:us-east-1:xxxxxxxx:function:xxxxxx:snapstart",
            "deadlineTimeInMs": 1714058111681,
            "logger": {
                "logFiltering": {
                    "minimumLogLevel": "UNDEFINED"
                },
                "logFormatter": {},
                "logFormat": "TEXT"
            }
        },
        "id": "e885c6da-be3c-b360-a61d-35d5efaba113",
        "aws-event": true,
        "timestamp": 1714057212214
    }
}
2024-04-25T10:46:00.405-05:00 ERROR 27452 --- [           main] c.l.cloud.simulator.StartAwsRuntime      : Error:

java.lang.ClassCastException: class java.util.LinkedHashMap cannot be cast to class java.lang.String (java.util.LinkedHashMap and java.lang.String are in module java.base of loader 'bootstrap')
      at org.springframework.cloud.function.adapter.aws.AWSLambdaUtils.generateMessage(AWSLambdaUtils.java:122) ~[spring-cloud-function-adapter-aws-4.1.1.jar:4.1.1]
      at org.springframework.cloud.function.adapter.aws.AWSLambdaUtils.generateMessage(AWSLambdaUtils.java:97) ~[spring-cloud-function-adapter-aws-4.1.1.jar:4.1.1]
      at org.springframework.cloud.function.adapter.aws.FunctionInvoker.handleRequest(FunctionInvoker.java:89) ~[spring-cloud-function-adapter-aws-4.1.1.jar:4.1.1]
      at com.xxxxx.cloud.simulator.StartAwsRuntime.main(StartAwsRuntime.java:29) ~[classes/:na]


Process finished with exit code 0`

@olegz
Copy link
Contributor

olegz commented Apr 26, 2024

What would help if you said initially that it is AWS related. That said, what is the signature of your function? This appears to be conversion issue so I need to know.

@srunnoe
Copy link
Author

srunnoe commented Apr 26, 2024

Here is a stripped down version.

`@Component
@slf4j
public class DemoFunction implements Function<Message, Message>{

public Message<String> apply(Message<String> message) {

    log.debug("Here I am");

    return null;
}

}`

@olegz
Copy link
Contributor

olegz commented Apr 30, 2024

What does this event represent? I mean what AWS event?

@olegz olegz added this to the 4.2 milestone Apr 30, 2024
@olegz olegz added the AWS label Apr 30, 2024
@olegz olegz self-assigned this Apr 30, 2024
@olegz olegz closed this as completed in 1787df8 May 1, 2024
@olegz olegz modified the milestones: 4.2, 4.1.2 May 1, 2024
natedanner pushed a commit to natedanner/spring-cloud__spring-cloud-function that referenced this issue May 20, 2024
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

2 participants