Manual configuration with a Lambda function

At the moment, our AWS Lambda-based integrations do not support working with test events. This functionality is in development.

Create a new Lambda function

This Lambda function will collect AppRunner logs and sends them to Logz.io in bulk over HTTPS.

Open the AWS Lambda Console, and click Create function. Choose Author from scratch, and use this information:

  • Name: We suggest adding the log type to the name, but you can name this function whatever you want.
  • Runtime: Choose Python 3.7
  • Role: Click Create new role from template(s). Then, from the Policy Templates list, select Basic Edge Lambda permissions.

Click Create Function (bottom right corner of the page). After a few moments, you’ll see configuration options for your Lambda function.

You’ll need this page later on, so keep it open.

Zip the source files

Clone the AppRunner Logs Shipper - Lambda project from GitHub to your computer, and zip the Python files in the src/ folder.

git clone https://github.com/logzio/logzio_aws_serverless.git \
&& cd logzio_aws_serverless/python3/apprunner/ \
&& mkdir -p dist/python3/shipper; cp -r ../shipper/shipper.py dist/python3/shipper \
&& cp src/lambda_function.py dist \
&& cd dist/ \
&& zip logzio-apprunner lambda_function.py python3/shipper/*

You’ll upload logzio-apprunner.zip in the next step.

Upload the zip file and set environment variables

In the Function code section of Lambda, find the Code entry type list. Choose Upload a .ZIP file from this list.

Click Upload, and choose the zip file you created earlier (logzio-apprunner.zip).

In the Environment variables section, set your Logz.io account token, URL, and log type, and any other variables that you need to use.

Environment variables
Parameter Description Required/Default
TOKEN Your Logz.io account token. Replace <<LOG-SHIPPING-TOKEN>> with the token of the account you want to ship to. Required
REGION Your two-letter Logz.io account region code. Defaults to US East. Required only if your Logz.io region is different than US East. You can find your region code in the Available regions table. Required. DEFAULT: blank (US East)
URL (Deprecated) Use REGION instead. --
TYPE The log type you’ll use with this Lambda. This can be a built-in log type, or a custom log type. You should create a new Lambda for each log type you use. logzio_apprunner_lambda
FORMAT 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. text
COMPRESS Set to true to compress logs before sending them. Set to false to send uncompressed logs. false
ENRICH Enrich AppRunner events with custom properties, formatted as key1=value1;key2=value2. --
Configure the function’s basic settings

In Basic settings, we recommend starting with these settings:

  • Memory: 512 MB
  • Timeout: 1 min 0 sec

These default settings are just a starting point. Check your Lambda usage regularly, and adjust these values if you need to.

Default settings

By default, we do not send logs of type START, END, REPORT.

If you prefer to send all log types, replace the method _parse_apprunner_log in the Lambda function with the following:

def _parse_apprunner_log(log, additional_data):
    # type: (dict, dict) -> bool
    _add_timestamp(log)
    if LAMBDA_LOG_GROUP in additional_data['logGroup']:
        _extract_lambda_log_message(log)
    log.update(additional_data)
    _parse_to_json(log)
    return True
Set the AppRunner Logs event trigger
  1. Find the Add triggers list (left side of the Designer panel). Choose CloudWatch Logs from this list.

  2. Below the Designer, you’ll see the Configure triggers panel. In the Log groups, search for the AppRunner option and select it as the trigger for the Lambda function.

  3. Type a Filter name (required) and Filter pattern (optional).

  4. Click Add, then Save at the top of the page.

Check Logz.io for your logs

Give your logs some time to get from your system to ours, and then open Kibana.

If you still don’t see your logs, see log shipping troubleshooting.

Automated CloudFormation deployment

At the moment, our AWS Lambda-based integrations do not support working with test events. This functionality is in development.

Before you begin, you’ll need: AWS CLI, an S3 bucket to store the CloudFormation package

Zip the source files

Clone the AppRunner Logs Shipper - Lambda project from GitHub to your computer, and zip the Python files in the src/ folder.

git clone https://github.com/logzio/logzio_aws_serverless.git \
&& cd logzio_aws_serverless/python3/apprunner/ \
&& mkdir -p dist/python3/shipper; cp -r ../shipper/shipper.py dist/python3/shipper \
&& cp src/lambda_function.py dist \
&& cd dist/ \
&& zip logzio-apprunner lambda_function.py python3/shipper/*
Create the CloudFormation package and upload to S3

Create the CloudFormation package using the AWS CLI. Replace <<YOUR-S3-BUCKET>> with the S3 bucket name where you’ll be uploading this package.

cd ../ \
&& aws cloudformation package \
  --template sam-template.yaml \
  --output-template-file cloudformation-template.output.yaml \
  --s3-bucket <<YOUR-S3-BUCKET>>
Deploy the CloudFormation package

Deploy the CloudFormation package using AWS CLI.

For a complete list of options, see the configuration parameters below the code block. 👇

aws cloudformation deploy \
--template-file $(pwd)/cloudformation-template.output.yaml \
--stack-name logzio-apprunner-logs-lambda-stack \
--parameter-overrides \
  LogzioTOKEN='<<LOG-SHIPPING-TOKEN>>' \
--capabilities "CAPABILITY_IAM"
Parameters
Parameter Description Required/Default
LogzioTOKEN Your Logz.io account token. Replace <<LOG-SHIPPING-TOKEN>> with the token of the account you want to ship to. Required
LogzioREGION Your two-letter Logz.io account region code. Defaults to US East. Required only if your Logz.io region is different than US East. You can find your region code in the Available regions table. Required. DEFAULT: blank (US East)
LogzioURL (Deprecated) Use LogzioREGION instead. Protocol, listener host, and port (for example, https://<<LISTENER-HOST>>:8071). The token of the account you want to ship to. --
LogzioTYPE The log type you’ll use with this Lambda. This can be a built-in log type, or a custom log type. You should create a new Lambda for each log type you use. logzio_apprunner_logs
LogzioFORMAT 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. text
LogzioCOMPRESS Set to true to compress logs before sending them. Set to false to send uncompressed logs. false
LogzioENRICH Enrich AppRunner events with custom properties, formatted as key1=value1;key2=value2. --
Default settings

By default, we do not send logs of type START, END, REPORT.

If you prefer to send all log types, replace the method _parse_apprunner_log in the Lambda function with the following:

def _parse_apprunner_log(log, additional_data):
    # type: (dict, dict) -> bool
    _add_timestamp(log)
    if LAMBDA_LOG_GROUP in additional_data['logGroup']:
        _extract_lambda_log_message(log)
    log.update(additional_data)
    _parse_to_json(log)
    return True
Set the AppRunner Logs event trigger
  1. Find the Add triggers list (left side of the Designer panel). Choose CloudWatch Logs from this list.

  2. Below the Designer, you’ll see the Configure triggers panel. In the Log groups, search for the AppRunner option and select it as the trigger for the Lambda function.

  3. Type a Filter name (required) and Filter pattern (optional).

  4. Click Add, then Save at the top of the page.

Check Logz.io for your logs

Give your logs some time to get from your system to ours, and then open Kibana.

If you still don’t see your logs, see log shipping troubleshooting.