awslabs / awslabs/aws-lambda-dart-runtime

Converting object to an encodable object failed for Instance of InvocationResult ApiGateway

Open
#28 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Dart
Stars
152
Forks
31
PR merge metrics
No merged PRs in 30d

Description

I am trying to follow api gateway example in readme
My code looks like
```
import 'package:aws_lambda_dart_runtime/aws_lambda_dart_runtime.dart';

void main() async {
print("hello from inside dart 1");

/// This demo's handling an API Gateway request.
final Handler helloApiGateway = (context, event) async {
print("hello from inside dart 2");
final response = {"message": "hello ${context.requestId}"};
print("hello from inside dart 3");

/// it returns an encoded response to the gateway
final resp = InvocationResult(
context.requestId, AwsApiGatewayResponse.fromJson(response));

print("hello from inside dart 4");
return resp;
};

/// The Runtime is a singleton. You can define the handlers as you wish.
Runtime()
..registerHandler("main.hello", helloApiGateway)
..invoke();
}
```
When endpoint invoked via curl, I get
`{"message": "Internal server error"}`
but I see all `hello...` prints in the lambda cloudwatch logs and request end without any exception.
When enpoint is invoked using AWS console for apigateway test UI, I see
```
Received response. Status: 200, Integration latency: 24 ms
Thu May 27 23:15:24 UTC 2021 : Endpoint response headers: {Date=Thu, 27 May 2021 23:15:24 GMT, Content-Type=application/json, Content-Length=128, Connection=keep-alive, x-amzn-RequestId=d71971ef-c9f7-4999-a306-2cec2aee846d, X-Amz-Function-Error=Unhandled, x-amzn-Remapped-Content-Length=0, X-Amz-Executed-Version=$LATEST, X-Amzn-Trace-Id=root=1-60b0280c-20ab219fdb20cbc96a699b53;sampled=0}
Thu May 27 23:15:24 UTC 2021 : Endpoint response body before transformations: {"errorMessage":"Converting object to an encodable object failed: Instance of 'InvocationResult'","errorType":"InvocationError"}
Thu May 27 23:15:24 UTC 2021 : Lambda execution failed with status 200 due to customer function error: Converting object to an encodable object failed: Instance of 'InvocationResult'. Lambda request id: d71971ef-c9f7-4999-a306-2cec2aee846d
Thu May 27 23:15:24 UTC 2021 : Method completed with status: 502
```
I tried changing line
`return resp;` to `ut8.encode(json.encode(resp))` and a few other things. No luck.
I am not sure what to do. Any help.

I am deploying using serverless.
I had to set the runtime as `provided.al2` since it would not do it with runtime as `dart`

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.