If your Lambda function has a terminating error, AWS Lambda recognizes the failure, serializes the error information into JSON, and returns it.
Consider the following PowerShell script example statement:
throw 'The Account is not found'
When you invoke this Lambda function, it throws a terminating error, and AWS Lambda returns the following error message:
{
"errorMessage": "The Account is not found",
"errorType": "RuntimeException"
}
Note the errorType
is RuntimeException
, which is the default exception thrown by PowerShell. You can use custom error types by throwing the error like this:
throw @{'Exception'='AccountNotFound';'Message'='The Account is not found'}
The error message is serialized with errorType
set to AccountNotFound
:
{
"errorMessage": "The Account is not found",
"errorType": "AccountNotFound"
}
If you don't need an error message, you can throw a string in the format of an error code. The error code format requires that the string starts with a character and only contain letters and digits afterwards, with no spaces or symbols.
For example, if your Lambda function contains the following:
throw 'AccountNotFound'
The error is serialized like this:
{
"errorMessage": "AccountNotFound",
"errorType": "AccountNotFound"
}