question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Exception when to create request via aws lambda invoke

See original GitHub issue
  • Framework version: XX
  • Implementations: Jersey / Spring / Spring Boot / Spark

Scenario

Using
aws lambda invoke
–invocation-type RequestResponse
–function-name SomeFunction
–region us-east-1
–payload file://file-path/input.txt
–profile adminuser
outputfile.txt

Expected behavior

Mapping the request which is NOT from API gateway proxy mode to Spring Request

Actual behavior

Exception

Steps to reproduce

Full log output

com.amazonaws.serverless.proxy.internal.LambdaContainerHandler
stack_trace : "com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.lang.String` out of START_OBJECT token^@ 
 at [Source: (lambdainternal.util.NativeMemoryAsInputStream); line: 1, column: 1412] (through reference chain: com.amazonaws.serverless.proxy.model.AwsProxyRequest[\"body\"])^@
\tat com.fasterxml.jackson.databind.exc.MismatchedInputException.from(MismatchedInputException.java:63)^@
\tat com.fasterxml.jackson.databind.DeserializationContext.reportInputMismatch(DeserializationContext.java:1342)^@
\tat com.fasterxml.jackson.databind.DeserializationContext.handleUnexpectedToken(DeserializationContext.java:1138)^@
\tat com.fasterxml.jackson.databind.DeserializationContext.handleUnexpectedToken(DeserializationContext.java:1092)^@
\tat com.fasterxml.jackson.databind.deser.std.StringDeserializer.deserialize(StringDeserializer.java:63)^@
\tat com.fasterxml.jackson.databind.deser.std.StringDeserializer.deserialize(StringDeserializer.java:10)^@
\tat com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet(MethodProperty.java:127)^@
\tat com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:288)^@
\tat com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:151)^@
\tat com.fasterxml.jackson.databind.ObjectReader._bindAndClose(ObjectReader.java:1611)^@
\tat com.fasterxml.jackson.databind.ObjectReader.readValue(ObjectReader.java:1188)^@
\tat com.amazonaws.serverless.proxy.internal.LambdaContainerHandler.proxyStream(LambdaContainerHandler.java:199)^@
\tat com.demo.StreamLambdaHandler.handleRequest(StreamLambdaHandler.java:46)^@
\tat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)^@
\tat sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)^@
\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)^@
\tat java.lang.reflect.Method.invoke(Method.java:498)^@
\tat lambdainternal.EventHandlerLoader$StreamMethodRequestHandler.handleRequest(EventHandlerLoader.java:350)^@
\tat lambdainternal.EventHandlerLoader$2.call(EventHandlerLoader.java:888)^@
\tat lambdainternal.AWSLambda.startRuntime(AWSLambda.java:283)^@
\tat lambdainternal.AWSLambda.<clinit>(AWSLambda.java:64)^@
\tat java.lang.Class.forName0(Native Method)^@
\tat java.lang.Class.forName(Class.java:348)^@
\tat lambdainternal.LambdaRTEntry.main(LambdaRTEntry.java:94)^@

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:14

github_iconTop GitHub Comments

1reaction
sapessicommented, Jul 7, 2018

No, it only supports specific types. I envision you doing something like this (using Jersey as an example):

public class MyLambdaHandler implements RequestHandler<CustomRequestType, CustomResponseType> {
    private static final ResourceConfig jerseyApplication = new ResourceConfig()
                                                             .packages("com.amazonaws.serverless.sample.jersey")
                                                             .register(JacksonFeature.class);
    private static final JerseyLambdaContainerHandler<AwsProxyRequest, AwsProxyResponse> handler
            = JerseyLambdaContainerHandler.getAwsProxyHandler(jerseyApplication);

    @Override
    public CustomResponseType handleRequest(CustomRequestType input, Context context)
            throws IOException {
        AwsProxyResponse resp = handler.proxy(this.translateRequest(input));

        // method implementation omitted for brevity
        CustomResponseType finalResp = this.translateResponse(resp);
        // just in case it wasn't closed by the mapper
        return finalResp;
    }

    private AwsProxyRequest translateRequest(CustomRequestType customReq) {
        AwsProxyRequest newReq = new AwsProxyRequest();
        newReq.setPath(customReq.getPath());
        ...
        return newReq;
    }
}
0reactions
sapessicommented, Jun 26, 2019

Resolving this since we have also created the wiki guide.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Invoke - AWS Lambda - AWS Documentation
Invokes a Lambda function. You can invoke a function synchronously (and wait for the response), or asynchronously. To invoke a function asynchronously, set...
Read more >
AWS Lambda function errors in Java
This page describes how to view Lambda function invocation errors for the Java runtime using the Lambda console and the AWS CLI.
Read more >
Error handling and automatic retries in AWS Lambda
When you invoke a function, two types of error can occur. Invocation errors occur when the invocation request is rejected before your function...
Read more >
AWS Lambda function errors in C# - AWS Lambda
This page describes how to view Lambda function invocation errors for the C# runtime using the Lambda console and the AWS CLI.
Read more >
Troubleshoot invocation issues in Lambda
When you invoke a Lambda function, Lambda validates the request and checks for scaling capacity before sending the event to your function or, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found