AppSync request mapping template errors not logged in CloudWatch

0

I have a simple resolver that has a simple Lambda function as a data source. This function always throws an error (to test out logging). The resolver has request mapping template enabled and it is configured as follows:

$util.error("request mapping error 1")

The API has logging configured to be as verbose as possible yet I cannot see this request mapping error 1 from my CloudWatch logs in RequestMapping log type:

{
    "logType": "RequestMapping",
    "path": [
        "singlePost"
    ],
    "fieldName": "singlePost",
    "resolverArn": "xxx",
    "requestId": "bab942c6-9ae7-4771-ba45-7911afd262ac",
    "context": {
        "arguments": {
            "id": "123"
        },
        "stash": {},
        "outErrors": []
    },
    "fieldInError": false,
    "errors": [],
    "parentType": "Query",
    "graphQLAPIId": "xxx"
}

The error is not completely lost because I can see this error in the query response:

{
  "data": {
    "singlePost": null
  },
  "errors": [
    {
      "path": [
        "singlePost"
      ],
      "data": null,
      "errorType": null,
      "errorInfo": null,
      "locations": [
        {
          "line": 2,
          "column": 3,
          "sourceName": null
        }
      ],
      "message": "request mapping error 1"
    }
  ]
}

When I add $util.appendError("append request mapping error 1") to the request mapping template so it looks like this:

$util.appendError("append request mapping error 1")
$util.error("request mapping error 1")

Then the appended error appears in the RequestMapping log type but the errors array is still empty:

{
    "logType": "RequestMapping",
    "path": [
        "singlePost"
    ],
    "fieldName": "singlePost",
    "resolverArn": "xxx",
    "requestId": "f8eecff9-b211-44b7-8753-6cc6e269c938",
    "context": {
        "arguments": {
            "id": "123"
        },
        "stash": {},
        "outErrors": [
            {
                "message": "append request mapping error 1"
            }
        ]
    },
    "fieldInError": false,
    "errors": [],
    "parentType": "Query",
    "graphQLAPIId": "xxx"
}

When I do the same thing with response mapping template then everything works as expected (errors array contains $util.error(message) and outErrors array contains $util.appendError(message) messages.

  1. Is this working as expected so the $util.error(message) will never show up in CloudWatch logs?
  2. Under what conditions will errors array in RequestMapping log type be populated?
  3. Bonus question: can the errors array contain more than 1 item for either RequestMapping or ResponseMapping log types?
Keine Antworten

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen