Appsync with go lambda resolver error handling

Viewed 51

I am using AppSync > Lambda resolver (using golang) > Dynamodb

I've looked everyone for more information on error handling with them. To start with, it appears as if AppSync doesn't rely on status codes coming back from the lambda resolver to indicate if there was an issue. Instead, we return an error in the lambda function

i.e. func(event CustomEventStruct) (map[string]any, error)

Now, if I return an error in this, it looks like I'm only able to control the message. AppSync also appears to have an "errorType" at the minimum.

Is there a way to control the error type, potentially a status code (though I doubt it from what I've read) and the errorMessage?

1 Answers

After doing some digging, I found that there is an error struct located here:

"github.com/aws/aws-lambda-go/lambda/messages"

There is a struct:

//nolint:stylecheck
type InvokeResponse_Error struct {
    Message string `json:"errorMessage"`
    Type string `json:"errorType"`
    StackTrace []*InvokeResponse_Error_StackFrame `json:"stackTrace,omitempty"`
    ShouldExit bool `json:"-"`
}

It expects a struct with the json tags json:"errorType" and json:"errorMessage" to control the return values to AppSync.

Related