Skip to content

Instantly share code, notes, and snippets.

@luca-m
Last active June 26, 2023 09:13
Show Gist options
  • Save luca-m/6261ce5a1309c64f42f413e1aca1cd60 to your computer and use it in GitHub Desktop.
Save luca-m/6261ce5a1309c64f42f413e1aca1cd60 to your computer and use it in GitHub Desktop.
AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Description: "This is an AWS Lambda function that collects CloudWatch logs and sends them to Logz.io in bulk, over HTTP."
Parameters:
logzioListener:
Type: "String"
Description: "The Logz.io listener URL for your region. You can find explanations here: https://docs.logz.io/user-guide/accounts/account-region.html"
Default: ""
logzioToken:
Type: "String"
Description: "Logz.io account token."
logzioType:
Type: "String"
Description: "The log type you'll use with this Lambda.
Please note that you should create a new Lambda for each log type you use.
This can be a built-in log type, or your custom log type"
Default: "logzio_cloudwatch_lambda"
logzioFormat:
Type: "String"
Description: "JSON or text.
If json, the lambda function will attempt to parse the message field as JSON
and populate the event data with the parsed fields."
Default: "text"
AllowedValues:
- "text"
- "json"
logzioCompress:
Type: "String"
Description: "If true, the Lambda will send compressed logs. If false, the Lambda will send uncompressed logs."
Default: "true"
AllowedValues:
- "true"
- "false"
logzioEnrich:
Type: "String"
Description: "Enriches the CloudWatch events with custom properties at ship time. The format is `key1=value1;key2=value2`. By default is empty."
Default: ""
logGroup:
Type: "String"
Description: "CloudWatch Log Group name from where you want to send logs."
Default: ""
Outputs:
LogzioCloudwatchLogsLambda:
Description: "Logz.io CW logs lambda ARN"
Value: !GetAtt LogzioCloudwatchLogsLambda.Arn
Resources:
LogzioCloudwatchLogsLambda:
Type: 'AWS::Serverless::Function'
Properties:
Runtime: python3.7
Handler: lambda_function.lambda_handler
CodeUri:
Bucket: logzio-aws-integrations-us-east-1
Key: cloudwatch-auto-deployment/1.1.0/logzio-cloudwatch.zip
FunctionName: logzio-cloudwatch-log-shipper
MemorySize: 512
Timeout: 60
Events:
LOsubscription0:
Type: CloudWatchLogs
Properties:
LogGroupName: !Ref logGroup
FilterPattern: "" #Match everything
Environment:
Variables:
LISTENER_URL: !Ref logzioListener
TOKEN: !Ref logzioToken
TYPE: !Ref logzioType
FORMAT: !Ref logzioFormat
COMPRESS: !Ref logzioCompress
ENRICH: !Ref logzioEnrich
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment