AWS CloudWatch & AWS Lambda

How to start logging with AWS CloudWatch through LogDNA.

The LogDNA AWS CloudWatch integration relies on AWS Lambda to route your CloudWatch logs to LogDNA.

Configure the LogDNA AWS Lambda function

  1. Start with this link and click Create function. On the following page, select Author from scratch
  2. Insert the following basic information and then select Create function:
  • Function Name: logdna_cloudwatch (you can choose what to name it)
  • Runtime: Node.js 14.x
  1. Edit the Lambda function details
  • Click the Actions dropdown and select: Upload a .ZIP file
  • Upload our LogDNA lambda function .ZIP file
  1. In the Environment variables block, edit the following details:
  • Environment variables:
    LOGDNA_HOSTNAME: Alternative Host Name (Optional)
    LOGDNA_TAGS: Comma-separated Tags (Optional)
    BASE_URL: Custom Ingestion URL (Optional)
  1. In the Basic settings block, edit the following details:
  • Handler: index.handler
  • Runtime: Node.js 14.x
  1. For Execution role, assign an IAM user with basic execution permissions by choosing an existing role and selecting a role that has permissions to upload logs to Amazon CloudWatch logs.

Configure your AWS CloudWatch Log Group

You have the option of connecting your AWS CloudWatch Log Groups within the Lambda function console or in your CloudWatch console.

In Lambda Function

  1. Add CloudWatch Logs as a Trigger and click it to Configure
  1. Select the CloudWatch Log Group to be sent to LogDNA. Note: You must have already created a log group within Cloudwatch. Click on Log Groups on the left sidebar in your CloudWatch dashboard and create log stream.
  2. Choose your own 'Filter name' and make sure 'Enable trigger' is checked.
  3. Repeat steps 1-3 to add multiple log groups.

Alternatively in CloudWatch

  1. Select the Log Group to be sent to LogDNA
  2. Select the action Subscription filters and then Create Lambda subscription filter
  3. Choose Destination: Select the Lambda function created above, i.e. logdna_cloudwatch
  4. Configure Log Format and Filters: Choose JSON as a log format
  5. Review your settings to Start Streaming

Validate and Test Your Lambda Function

In your Lambda function console, you can configure a test event to see if your lambda function was set up correctly

  1. Select Configure test events
  1. Create a new test event and select the Event template Hello World and name your test event
  2. Replace the sample event data with this:
    "awslogs": {
        "data": "H4sIAAAAAAAAEzWQQW+DMAyF/wrKmaEkJCbhhjbWCzuBtMNUVSmkNBIQRMKqqep/X6Cb5Ivfs58++45G7ZzqdfMza5Sjt6IpTh9lXReHEsXI3ia9BJnQlHHIhMSEBnmw/WGx6xwcp8Z50M9uN2q/aDUGx2vn/5oYufXs2sXM3tjp3QxeLw7lX6hS47lTz6lTO9i1uynfXkOMe5lsp9Fxzyy/9eS3hTsyXYhOGVCaEsBSgsyEYBkGzrDMAIMQlAq+gQIQSjFhBFgqJOUMAog34WAfoFFOOM8kA0Y5SSH+f0SIb67GRaHq/baosn1UmUlHF7tErxvk5wa56b2Z+iRJ0OP4+AWj9ITzSgEAAA=="
  1. Hit Test
  2. If execution succeeds, you will see a message similar to this:

If you see errors, the most common one is not adding in the ingestion key in the environment variables


Execution result: failed

"errorMessage": "Missing LogDNA Ingestion Key"

  1. Log in to your LogDNA console to see the log line from your Lambda function test.