The LogDNA AWS CloudWatch integration relies on AWS Lambda to route your CloudWatch Logs to LogDNA.
- Create a new Lambda function and select
Author from scratch - Click on the Lambda function to edit the details:
- Code entry type:
Upload a .ZIP file - Upload our LogDNA Lambda function .ZIP File.
- Handler:
index.handler - Runtime:
Node.js 20.x
If this function is being used to stream from gzipped files:
- Set
Timeoutto, at least,10 seconds. - Set
Memorylimit to, at least,128 MB.
Notes:
- The recommended number of retries is 0 because retrying lambda execution can result in duplicate logs. It can be modified in
Configuration > Asynchronous invocation.
Add CloudWatch Logs as a trigger with the following configuration:
- Select the
CloudWatch Log Groupto be sent to LogDNA. - Choose your own custom
Filter Name. - Optional
Filter Patternoption can be used to filter the logs before shipping to LogDNA.
Notes:
- You can specify only one
CloudWatch Log Groupin one trigger.
For Execution role, assign a role that has the following policies:
Set LOGDNA_KEY variable to your LogDNA ingestion key. Optionally, you can use the following environment variables:
LOGDNA_HOSTNAME: Alternative Host NameLOGDNA_TAGS: Comma-separated TagsLOGDNA_URL: Custom Ingestion URLLOG_RAW_EVENT: Settinglineto Rawevent.message(Default: false):- It can be enabled by setting
LOG_RAW_EVENTtoYESorTRUE - Enabling it moves the following
event-relatedmetadata from thelinefield to themetafield:event.type:messageTypeofCloudWatch Logencoded insideawslogs.datainbase64event.id:idof eachCloudWatch Logencoded insideawslogs.datainbase64log.group:LogGroupwhere the log is coming fromlog.stream:LogStreamwhere the log is coming from
- It can be enabled by setting
Notes: The following optional environment variables can also be used to tune this Lambda function for specific use cases.
LOGDNA_MAX_REQUEST_TIMEOUT: Time limit (inmilliseconds) for requests made by this HTTP Client (Default: 30000)LOGDNA_FREE_SOCKET_TIMEOUT: How long (inmilliseconds) to wait for inactivity before timing out on the free socket (Default: 300000)LOGDNA_MAX_REQUEST_RETRIES: The maximum number of retries for sending a line when there are network failures (Default: 5)LOGDNA_REQUEST_RETRY_INTERVAL: How frequently (inmilliseconds) to retry for sending a line when there are network failures (Default: 100)
Enabling monitoring means forwarding the metrics and logs about the execution of the CloudWatch Lambda function to CloudWatch. You can also create and use a separate CloudWatch Lambda function to monitor the performance of this CloudWatch Lambda function.
You can test the configuration and code package using the following test input containing the sample event data:
{ "awslogs": { "data": "H4sIAAAAAAAAEzWQQW+DMAyF/wrKmaEkJCbhhjbWCzuBtMNUVSmkNBIQRMKqqep/X6Cb5Ivfs58++45G7ZzqdfMza5Sjt6IpTh9lXReHEsXI3ia9BJnQlHHIhMSEBnmw/WGx6xwcp8Z50M9uN2q/aDUGx2vn/5oYufXs2sXM3tjp3QxeLw7lX6hS47lTz6lTO9i1uynfXkOMe5lsp9Fxzyy/9eS3hTsyXYhOGVCaEsBSgsyEYBkGzrDMAIMQlAq+gQIQSjFhBFgqJOUMAog34WAfoFFOOM8kA0Y5SSH+f0SIb67GRaHq/baosn1UmUlHF7tErxvk5wa56b2Z+iRJ0OP4+AWj9ITzSgEAAA==" } }Copyright © LogDNA, released under an MIT license. See the LICENSE file and https://opensource.org/licenses/MIT
Contributions are always welcome. See the contributing guide to learn how you can help.
Happy Logging!