0.0.7 • Published 6 years ago

serverless-logs-plugin v0.0.7

Weekly downloads
4
License
MIT
Repository
github
Last release
6 years ago

serverless-logs-plugin

A serverless framework plugin for AWS to add log retention and the resource to subscribe log groups

Usage

Install from npm:

npm i --save serverless-logs-plugin

In serverless.yml add the plugin:

plugins:
  - serverless-logs-plugin

In serverless.yml add the configuration:

...
provider:
  logsPlugin:
    LogGroup:
      RetentionInDays: 14  # optional, default: 90
    SubscriptionFilter: # optional, default: no SubscriptionFilter resource is added
      DestinationArn: my-destination-arn
      FilterPattern: my-filtern-pattern  # optional, default: '{ $.NotExistingField NOT EXISTS }'
      RoleArn: my-role-arn  # optional, default: null
    additionalSubscriptions: # optional, default: no additional SubscriptionFilter
      - DependsOn: ElasticBeanstalkApp
        LogGroupNames:
          - /aws/elasticbeanstalk/myapp/var/log/eb-activity.log
          - /aws/elasticbeanstalk/myapp/var/log/nginx/access.log
          - /aws/elasticbeanstalk/myapp/var/log/nginx/error.log
          - /aws/elasticbeanstalk/myapp/var/log/web-1.error.log
          - /aws/elasticbeanstalk/myapp/var/log/web-1.log
...

As a result, the plugin will produce, for each lambda function a resource to set the RetentionInDays to the log group and a resource to subscribe the log group:

    "MyFunctionLogGroup": {
      "Type": "AWS::Logs::LogGroup",
      "Properties": {
        "LogGroupName": "/aws/lambda/MyFunction",
        "RetentionInDays": 90
      }
    },
    "MyFunctionSubscriptionFilter": {
      "Type": "AWS::Logs::SubscriptionFilter",
      "DependsOn": "MyFunctionLambdaFunction",
      "Properties": {
        "DestinationArn": "my-destination-arn",
        "LogGroupName": "/aws/lambda/MyFunction",
        "FilterPattern": "{ $.NotExistingField NOT EXISTS }"
      }
    }  

For each additionalSubscriptions, a subscription resource is produced:

    "AwselasticbeanstalkmyappvarlogwebDash1logSubscriptionFilter": {
      "Type": "AWS::Logs::SubscriptionFilter",
      "DependsOn": "ElasticBeanstalkApp",
      "Properties": {
        "DestinationArn": "my-destination-arn",
        "LogGroupName": "/aws/elasticbeanstalk/myapp/var/log/web-1.log",
        "FilterPattern": "{ $.NotExistingField NOT EXISTS }"
      }
    }
0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago