aws-amplify / aws-amplify/amplify-cli
Java function does not bind input arguments
- Dominant language
- TypeScript
- Stars
- 2.9k
- Forks
- 825
- Avg merge
- 11d 23h
- Merged PRs (30d)
- 2
Description
> **Note**: If your issue/bug is regarding the AWS Amplify Console service, please log in the
> [Amplify Console GitHub Issue Tracker](https://github.com/aws-amplify/amplify-console/issues)
**Describe the bug**
Java Runtime Lambda does not receive caller parameters. The arguments inside the function (RequestClass) are null.
It is happening when using Mock API and when the Function is deployed in AWS.
**Amplify CLI Version**
4.41.2 and 4.42.0
**To Reproduce**
1. Create a function for Java runtime using amplify add function. _It will use the default template (Hello World Template)_
2. Link the function created in the previous step from a GraphQL query using the directive @function (the default function receives two parameters: firstName, lastName. And it returns an object Greetings.
3. Execute GraphiQL locally (using amplify mock API) and call the new query connected to the function defined in step 1. Pass some parameters in the call.
- The function will return null in the args placeholder despite including some values in the query call.
**Expected behavior**
The args included in the query call should be serialized into the RequestClass and passed to the function, but instead, the values inside RequestClass are null.
**Screenshots**
- Function creation

- It generates the Hello World Template:

- GraphQL set up (adding @function and the return type)

- Execution from GraphiQL

**Desktop (please complete the following information):**
- OS: [e.g. Mac/Windows/Ubuntu]
macOS Big Sur
- Node Version. You can use `node -v` to check the node version on your system
v14.8.0 (no relevant)
**Log output**
Include any relevant log output under `~/.amplify/logs/amplify-cli-.log`
```
2021-02-11T02:25:18.814Z|info : amplify version core {"version":true,"yes":false}
2021-02-11T02:26:16.556Z|info : amplify add function test2
2021-02-11T02:26:50.614Z|info : amplify upgrade core
2021-02-11T02:27:19.947Z|info : amplify add function
2021-02-11T02:31:30.401Z|info : amplify api mock
```
**Additional context**
It seems like the binding into the RequestClass is not happening. I tried to log the fields, and they are null
But if you change the handler to receive the full event, you can log its content. The problem is that event.arguments are not being mapped into RequestClass:
- Handler changes to try to receive the event
```
public class LambdaRequestHandler implements RequestHandler, String>{
@Override
public String handleRequest(Map event, Context context) {
LambdaLogger logger = context.getLogger();
logger.log("event:");
logger.log(event.toString());
return "hello world";
}
}
```
- Event log captured
```
{typeName=Query, fieldName=echo, arguments={firstName=test, lastName=2}, identity={sub=7d8ca528-4931-4254-9273-ea5ee853f271, issuer=https://cognito-idp.us-east-1.amazonaws.com/us-east-1_fake, cognito:username=user1, username=user1, sourceIp=::ffff:192.168.1.75, claims={sub=7d8ca528-4931-4254-9273-ea5ee853f271, email_verified=true, iss=https://cognito-idp.us-east-1.amazonaws.com/us-east-1_fake, phone_number_verified=true, cognito:username=user1, aud=2hifa096b3a24mvm3phskuaqi3, event_id=b12a3e2f-7a36-493c-85b3-20d818bd78a1, token_use=id, auth_time=1.974264412E9, phone_number=+12062062016, exp=1.6130143013E10, iat=1.564264413E9, email=user@domain.com}, defaultAuthStrategy=ALLOW}, source=null, request={headers={host=192.168.1.75:20002, connection=keep-alive, content-length=121, accept=application/json, authorization=e.....OiEZfRJlE3cG90e0LLis1TGtg, user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 11_1_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.146 Safari/537.36, content-type=application/json, origin=http://192.168.1.75:20002, referer=http://192.168.1.75:20002/, accept-encoding=gzip, deflate, accept-language=en-GB,en;q=0.9,es;q=0.8}}, prev={result={}}}
```
Edit 20210211:
- The change to capture the full event works locally (using mock API) but it triggers an error when deployed. It was intended just to see in the args were present locally in the event. The error triggered when changing the signature of the handler and the execution is in AWS was:
```
An error occurred during JSON parsing: java.lang.RuntimeExceptionjava.lang.RuntimeException: An error occurred during JSON parsingCaused by: java.io.UncheckedIOException:
com.amazonaws.lambda.thirdparty.com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.lang.String` out of START_OBJECT token at [Source: (ByteArrayInputStream); line: 1, column: 52] (through reference chain: java.util.LinkedHashMap["arguments"]) at
com.amazonaws.services.lambda.runtime.serialization.factories.JacksonFactory$InternalSerializer.fromJson(JacksonFactory.java:184)Caused by: com.amazonaws.lambda.thirdparty.com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.lang.String` out of START_OBJECT token at [Source: (ByteArrayInputStream); line: 1, column: 52] (through reference chain: java.util.LinkedHashMap["arguments"]) at
com.amazonaws.lambda.thirdparty.com.fasterxml.jackson.databind.exc.MismatchedInputException.from(MismatchedInputException.java:59) at
com.amazonaws.lambda.thirdparty.com.fasterxml.jackson.databind.DeserializationContext.reportInputMismatch(DeserializationContext.java:1442) at
com.amazonaws.lambda.thirdparty.com.fasterxml.jackson.databind.DeserializationContext.handleUnexpectedToken(DeserializationContext.java:1216) at
.......
)
```
Contributor guide
Assessment
This issue has not been assessed yet.