Skip to content

Latest commit

 

History

History
71 lines (57 loc) · 1.73 KB

cloudwatch-log.md

File metadata and controls

71 lines (57 loc) · 1.73 KB

CloudWatch Log

Simple event definition

This will enable your Lambda function to be called by a Log Stream.

functions:
  myCloudWatchLog:
    handler: myCloudWatchLog.handler
    events:
      - cloudwatchLog: '/aws/lambda/hello'

Specifying a filter

Here's an example how you can specify a filter rule.

For more information about the filter pattern syntax, see Filter and Pattern Syntax

functions:
  myCloudWatchLog:
    handler: myCloudWatchLog.handler
    events:
      - cloudwatchLog:
          logGroup: '/aws/lambda/hello'
          filter: '{$.userIdentity.type = Root}'

Example

Update your serverless.yml file as follows and run serverless deploy.

functions:
  hello1:
    handler: handler.hello1
    events:
      - cloudwatchLog: '/aws/lambda/hello1'
  hello2:
    handler: handler.hello2
    events:
      - cloudwatchLog: '/aws/lambda/hello2'

Next up, edit serverless.yml and swap out the logGroup names. After that run serverless deploy again (the deployment will fail).

functions:
  hello1:
    handler: handler.hello1
    events:
      - cloudwatchLog: '/aws/lambda/hello2'
  hello2:
    handler: handler.hello2
    events:
      - cloudwatchLog: '/aws/lambda/hello1'