top of page

AWS - Serverless: <4> Error Handler & Logging

  • Writer: Anh Nguyen tuan
    Anh Nguyen tuan
  • Jul 8, 2022
  • 1 min read

1. Error Handler

  • When lambda throw an Exception, it will push into the destination defined in DeadLetterQueue properties.

  • Using a lambda function to listen this queue and handle this error.


ree

ErrorDLQueue:
    Type: AWS::SNS::Topic
ConsumeMsgFunction:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: customer
      Handler: com.anhnt.customer.DeliverMsg::onSNSMessage
      DeadLetterQueue:
        Type: SNS
        TargetArn: !Ref ErrorDLQueue

2. Logging

  • Go to AWS service 'Cloud watch' to check logs:


ree

  • For logging, you have 3 ways to log to 'cloud watch'

    • System.out.println;

    • LambdaLogger logger = context.getLogger();

    • Using Log4j library

Comments


bottom of page