Send logs to Amazon CloudWatch Logs

Coolify's built-in Amazon CloudWatch Logs log drain sends opted-in resource logs to a CloudWatch Logs log group. It uses the Docker awslogs logging driver, so the Docker daemon on the server sends the logs directly to AWS.

The short version

Give the Docker daemon on the server AWS credentials, save the log group and region on the server's Log Drains page, enable the Amazon CloudWatch Logs drain, then configure Log drain as described in Enable log draining for a resource and restart each resource you want to forward.


Before you start

AWS credentials for DockerThe Docker daemon on the server reads the credentials. Coolify does not store AWS keys.
IAM permissionsAllow the CloudWatch Logs actions that the Docker awslogs driver uses.
Validated serverUse the server that runs the resources and confirm it can reach the CloudWatch Logs endpoint of the region on port 443.

The CloudWatch drain does not use the coolify-log-drain Fluent Bit container. Coolify configures the Docker awslogs logging driver on each opted-in resource container instead.


Give Docker AWS credentials

The Docker daemon on the server reads the AWS credentials, not Coolify. Use one of these sources:

  • An IAM instance profile (instance role), if the server is an Amazon EC2 instance.
  • The AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables of the Docker service. Also set AWS_SESSION_TOKEN for temporary credentials.
  • The shared credentials file of the root user, /root/.aws/credentials.

For example, to set environment variables for a Docker service that systemd manages, create /etc/systemd/system/docker.service.d/aws-credentials.conf:

[Service]
Environment="AWS_ACCESS_KEY_ID=<access-key-id>"
Environment="AWS_SECRET_ACCESS_KEY=<secret-access-key>"

Then reload systemd and restart Docker:

sudo systemctl daemon-reload
sudo systemctl restart docker
Restarting Docker restarts containers

A restart of the Docker service stops and starts the containers on the server. Do this step in a maintenance window.


Set the IAM permissions

The credentials must allow these CloudWatch Logs actions:

ActionWhy the driver needs it
logs:CreateLogStreamCreates one log stream for each container.
logs:PutLogEventsSends the log events.
logs:CreateLogGroupCreates the log group if it does not exist. Not necessary if you create the log group before you enable the drain.

Example policy:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "logs:CreateLogGroup",
        "logs:CreateLogStream",
        "logs:PutLogEvents"
      ],
      "Resource": "*"
    }
  ]
}

To limit the policy, replace "*" with the ARN of the log group and its log streams.


Configure CloudWatch in Coolify

Connect the server to CloudWatch Logs

Keep the drain disabled while editing its fields, then enable it after the values are saved.

1

Open the server Log Drains page

2

Enter the log group

3

Enter the stream prefix (optional)

4

Enter the region

5

Save the settings

6

Enable the drain

  • Open Servers, select the server that runs the resources, then open Log Drains.
  • In Amazon CloudWatch Logs, leave Status set to Disabled and enter the log group name in Log group, for example /coolify/production.
  • Optional: enter a value in Log stream prefix, for example docker/.
  • Enter the AWS region code in Region, for example us-east-1.
  • Select Save changes.
  • Set Status to Enabled. Coolify stops the coolify-log-drain container if it runs, because CloudWatch does not use it.

Only one server-level log drain can be enabled at a time. Disable another active destination before enabling Amazon CloudWatch Logs.

Coolify accepts these values:

FieldRequiredAccepted value
Log groupYes1 to 512 characters: letters, numbers, ., -, _, /, and #.
Log stream prefixNoUp to 256 characters: letters, numbers, ., -, _, /, and #.
RegionYesAn AWS region code, for example us-east-1 or eu-central-1. Coolify does not use a default region.
Enabling the drain is not an ingestion test

Coolify checks the field formats. It does not verify the AWS credentials, the IAM permissions, or the log group before showing the drain as enabled.


Enable a resource

Follow Enable log draining for a resource, then restart or redeploy the resource.

Coolify sets these awslogs options on the container:

OptionValue
awslogs-groupThe Log group value.
awslogs-regionThe Region value.
awslogs-create-grouptrue
tagThe Log stream prefix value followed by the container name.
modenon-blocking

The non-blocking mode prevents CloudWatch errors from blocking or stopping the container. If the driver cannot send logs, the container continues to run.


Log groups and log streams

  • Log group: The driver creates the log group if it does not exist. This requires logs:CreateLogGroup.
  • Log streams: The driver creates one log stream for each container. The stream name is the Log stream prefix value followed by the container name, for example docker/<container-name>. Without a prefix, the stream name is the container name.

The CloudWatch drain does not add the coolify.server_name or coolify.app_name fields that the Fluent Bit destinations add. Use the log stream name to identify the container.

Coolify does not set a retention period on the log group. Set the retention in CloudWatch Logs.


Verify delivery

  1. Cause the resource to write a recognizable message to stdout or stderr.
  2. Open CloudWatch Logs in the AWS console and select the log group and region that you entered in Coolify.
  3. Open the log stream of the container and search for the message.

Verification in CloudWatch Logs is required because Coolify does not perform a provider connection test.


Update the log group, prefix, or region

  1. Set Status to Disabled in the Amazon CloudWatch Logs section.
  2. Update Log group, Log stream prefix, or Region.
  3. Select Save changes.
  4. Set Status to Enabled again.
  5. Restart or redeploy the resources. Running containers keep the logging options that they had when Docker created them.
  6. Generate a new resource log and confirm that it arrives in the expected log group.

Fix missing logs

  1. Confirm Amazon CloudWatch Logs is the enabled server drain and the resource's Log drain setting is on.
  2. Confirm you restarted or redeployed the resource after enabling the setting.
  3. Confirm the Docker daemon has AWS credentials and that they allow the IAM actions in Set the IAM permissions.
  4. Confirm the region in Coolify is the region where you look for the log group.
  5. Confirm the container uses the awslogs driver:
docker inspect --format '{{.HostConfig.LogConfig.Type}}' <container-name>
  1. Inspect the Docker daemon logs on the resource server:
journalctl -u docker --since "15 minutes ago"

Credential, permission, and network errors appear in the Docker daemon logs. They do not appear in a coolify-log-drain container, because CloudWatch does not use it.


Continue with log drains

On this page