Error handler pambda.
npm i pambda-errorhandler
import { compose, createLambda } from 'pambda';
import { errorhandler } from 'pambda-errorhandler';
export const handler = createLambda(
compose(
// errorhandler not applied.
pambda1(),
errorhandler({}),
// errorhandler applied.
pambda2()
)
);
-
options.renderError
- The function with argument
(err, event, context, callback)
, called when an error occurs in subsequent Pambdas. - Default value is
defaultErrorResponse
.
- The function with argument
-
options.errorNotificationArn
- A topic ARN of SNS for publishing an error.
- Default value is
process.env.ERROR_NOTIFICATION_ARN
.
-
options.errorNotificationTopicName
- A topic name of SNS for publishing an error.
- If the
options.errorNotificationArn
is specified, this option is ignored.
If the options.errorNotificationArn
is used, such as the following configuration is needed in your SAM template:
Resources:
YourLambda:
Type: AWS::Serverless::Function
Properties:
Policies:
- SNSPublishMessagePolicy:
TopicName: yourSnsTopicName
Environment:
Variables:
ERROR_NOTIFICATION_ARN: !Sub "arn:aws:sns:${AWS::Region}:${AWS::AccountId}:yourSnsTopicName"
Default error handling function. Returns Internal Server Error response.
Also, log objects that have properties of event
and err
.
MIT