AWSTemplateFormatVersion: 2010-09-09 Transform: AWS::Serverless-2016-10-31 Description: > Log Processing utilities stack. Provides a dedicated Kinesis stream for log ingestion. Subscribe new and existing Lambda function logs named `Airline` to Kinesis and only log entries that have `REPORT` or `MONITORING` as strings Expire ALL log entries after 14 days Creates Custom Metrics for Memory Used, Size, and Estimated Cost for each function and version Also creates custom metrics based on "MONITORING|||||" format Resources: # Kinesis Stream that will receive Logs from CloudWatch Logs LogProcessingStream: Type: AWS::Kinesis::Stream Properties: RetentionPeriodHours: 48 ShardCount: 1 # Subscribe new and existing CloudWatch Log groups to ship logs to Kinesis SubscribeLogsToProcessingStream: Type: AWS::Serverless::Application Properties: Location: ApplicationId: arn:aws:serverlessrepo:us-east-1:374852340823:applications/auto-subscribe-log-group-to-arn SemanticVersion: 1.11.1 Parameters: # The ARN of the Lambda function or Kinesis stream to subscribe a newly created CloudWatch log group to DestinationArn: !Sub ${LogProcessingStream.Arn} ## Disables processing of own logs ExcludePrefix: "ProcessCustomMetricsAsync" # Uncomment to override default value # Only subscribe to functions created for this project ## Otherwise we'd override all CloudWatch Logs by subscribing to our Kinesis Prefix: "/aws/lambda/monitoring-app" # Uncomment to override default value # Only captures Custom Metrics and INFO|WARN|ERROR log events; reduces cost and unnecessary noise FilterPattern: "?INFO ?ERROR ?WARN ?REPORT ?MONITORING" # "{ $._logLevel != \"debug\" || $.MetricData IS TRUE }" in cases of custom consumer applications. # SAR App that will consume from Kinesis stream and create Custom Metrics ProcessCustomMetricsAsync: Type: AWS::Serverless::Application Properties: Location: ApplicationId: arn:aws:serverlessrepo:us-east-1:374852340823:applications/async-custom-metrics SemanticVersion: 1.7.0 Parameters: # What's the event source you will intend to use? If logs are pushed from CloudWatch Logs to Lambda directly, then use 'Lambda'. If logs are pushed to a Kinesis Stream first, then use 'Kinesis'. Other event sources are not supported (yet). EventSourceType: "Kinesis" # Uncomment to override default value # (optional) Only relevant to the Kinesis event source type. The ARN to the Kinesis stream to subscribe the function to. KinesisStreamArn: !Sub ${LogProcessingStream.Arn} # Uncomment to override default value # (optional) Only relevant to the Kinesis event source type. The batch size to use for the subscription. # KinesisStreamBatchSize: '100' # Uncomment to override default value # (optional) Timeout for the Lambda function that would ship metrics to CloudWatch. Defaults to 30s. # TimeoutSeconds: '30' # Uncomment to override default value # (optional) Whether to report init duration for Lambda functions as metrics. Allowed values are "true" or "false". RecordLambdaColdStartMetric: 'true' # Uncomment to override default value # (optional) Whether to report estimated cost for Lambda functions as metrics. Allowed values are "true" or "false". RecordLambdaCostMetric: 'true' # Uncomment to override default value # (optional) Whether to collect Lambda usage metrics (i.e. billed duration, memory size, max memory used) from the logs and turn them into metrics. Allowed values are "true" or "false". RecordLambdaUsageMetrics: 'true' # Uncomment to override default value # ProcessLogAndMetricsFunction: # Type: AWS::Serverless::Function # Properties: # Handler: src/handlers/index.handler # Description: Lambda function to parse logs from Kinesis Stream and either publish as CloudWatch Custom Metric or index logs on Elasticsearch. # Runtime: nodejs12.x # Timeout: 100 # Tracing: Active # MemorySize: 1024 # Environment: # Variables: # ENABLE_DEBUG: false # RECORD_LAMBDA_COLD_START_METRIC: true # RECORD_LAMBDA_COST_METRIC: true # Policies: #- ElasticsearchHttpPostPolicy: * # DomainName: * # - CloudWatchPutMetricPolicy: {} # Events: # LogProcessingStream: # Type: Kinesis # Properties: # Stream: !Sub ${LogProcessingStream.Arn} # StartingPosition: LATEST # BatchSize: 10 # MaximumBatchingWindowInSeconds: 10 # Enabled: true Outputs: LogProcessingStream: Value: !Sub ${LogProcessingStream.Arn} Description: Kinesis Stream used for log processing