
Amazon Athena is a serverless query service that analyzes data in Amazon S3 using SQL and supports federated queries across other data sources. It removes the need to deploy and manage query infrastructure, but it bills on-demand for SQL queries based on the amount of data scanned, and its catalog, permissions, and federated connectors integrate with AWS Glue, IAM, and Lambda.
Trino is an open-source distributed SQL query engine that queries data in object storage, relational databases, and other sources through connectors. Athena SQL engine version 3 builds on Trino, making Trino a close self-hosted alternative. A self-hosted deployment gives you control over the engine release, connector configuration, resource allocation, and data location, with infrastructure costs rather than per-query data scan charges.
This article covers deploying Trino on a single Linux server using Docker Compose as an alternative to Amazon Athena. It includes setting up a coordinator and two workers, configuring an Iceberg REST catalog with Object Storage, creating and querying Iceberg tables, and joining PostgreSQL data with Iceberg tables through federated queries. Additional topics include HTTPS and password authentication, resource groups, deployment verification, and migration from Amazon Athena.
Trino components closely correspond to Amazon Athena query processing and data access features, but the match is not always one-to-one. The following table pairs each Athena feature with its nearest Trino counterpart and notes the differences.
The Trino deployment architecture consists of:
Before you begin, you need to:
trino.example.com).This deployment runs a coordinator and two workers as separate containers on a single Linux server, all from the trinodb/trino:483 image. Each node keeps its configuration in its own etc/ directory.
Create the project directory with subdirectories.
coordinator/etc/: Holds the configuration for the trino-coordinator container, which accepts SQL queries, plans their execution, and assigns tasks to workers.worker-1/etc/: Holds the configuration for the trino-worker-1 container, which executes query tasks and reads data through connectors.worker-2/etc/: Holds the configuration for the trino-worker-2 container, which executes query tasks and reads data through connectors.catalog: Holds the connector properties files shared by all three containers.Navigate to the project directory.
The Iceberg REST catalog manages table registration and references to Iceberg metadata stored in Object Storage.
Create an Object Storage bucket named trino-warehouse in your subscription. Record the bucket name, endpoint hostname, access key, and secret key.
This guide uses trino-warehouse as the bucket name. If you choose a different name, replace trino-warehouse with your bucket name wherever it appears in the rest of this guide.
Create an environment file.
Add the following configuration.
Replace:
CATALOG_DB_PASSWORD with a strong password for the catalog database.OBJECT_STORAGE_ENDPOINT with your object storage hostname.OBJECT_STORAGE_REGION with the first label of the endpoint hostname, such as ams1 for ams1.vultrobjects.com.OBJECT_STORAGE_ACCESS_KEY and OBJECT_STORAGE_SECRET_KEY with your subscription's S3 credentials.Save and close the file.
Restrict access to the environment file.
Create the Docker Compose file.
Add the following configuration.
Save and close the file.
In this configuration:
catalog-db-data: Preserves catalog database records when you recreate containers.depends_on: Waits for PostgreSQL to accept connections before starting the REST catalog.CATALOG_WAREHOUSE: Sets the default storage location for Iceberg tables.CATALOG_S3_ENDPOINT and CATALOG_S3_PATH__STYLE__ACCESS: Configure access to the S3-compatible storage endpoint.Validate the Docker Compose configuration.
The command returns no output if the configuration is valid.
Start the services in detached mode.
Verify that services are running.
The output shows Up with (healthy) for the catalog-db container and Up for the iceberg-rest container.
Verify that the REST catalog responds.
The endpoint returns a JSON response containing defaults and overrides.
The coordinator accepts queries and assigns tasks to the workers. Each node uses a separate configuration directory with a unique node ID, while all three nodes share the same environment and discovery URI.
Create a node.properties file for each node.
Each file uses its node name as the node.id. The matching node.environment value allows the nodes to join the same cluster.
Create the coordinator configuration file.
Add the following configuration.
Save and close the file.
The discovery URI uses the coordinator's Docker Compose service name, trino-coordinator, so all three nodes can reach the same discovery service.
Create the first worker configuration file.
Add the following configuration.
Save and close the file.
The worker uses the same discovery URI as the coordinator and executes queries.
Copy the worker configuration to the second worker.
The workers share the same server configuration but retain their separate node.properties files.
Extract the default JVM configuration from the Trino image.
Open the JVM configuration file.
Replace the following two lines:
With:
Save and close the file.
This sets the maximum heap size of each Trino JVM to 2 GB. Increase the heap allocation for larger workloads while allowing memory to be used outside the JVM heap.
Copy the JVM configuration to the first worker.
Copy the JVM configuration to the second worker.
Docker Compose runs the coordinator and workers on the same network so they can communicate using service names. Each container mounts its own configuration directory and the shared catalog directory.
Create the catalog mount point inside each node's configuration directory.
These directories allow Docker to mount the shared catalog directory inside each read-only configuration mount.
Open the Docker Compose file.
Add the following services under the existing services: block, at the same indentation as catalog-db and iceberg-rest. Keep the existing services and top-level volumes: block unchanged.
Save and close the file.
Each container mounts its node configuration at /etc/trino and the shared connector configuration at /etc/trino/catalog. The mounts are read-only. Only the coordinator publishes a host port, bound to localhost.
The mem_limit setting caps each Trino container at 2.5 GB. This leaves 512 MB above the 2 GB JVM heap set in jvm.config for memory that Trino uses outside the heap, such as thread stacks and direct buffers. Increase mem_limit for each Trino service if your queries need more headroom. A container that restarts with exit code 137 has run out of memory and needs a higher limit. When you increase -Xmx, keep mem_limit about 25 percent above the heap size.
Validate the Docker Compose configuration.
The command returns no output if the configuration is valid.
Start the coordinator and workers.
Verify that services are running.
The output displays the containers with an Up status.
Query the coordinator to verify node registration.
The output lists three active nodes running version 483. The node with true in the coordinator column is the coordinator.
The Iceberg connector connects Trino to the REST catalog and reads table data from Object Storage. The shared catalog file provides the same connection settings to the coordinator and both workers.
Open the Docker Compose file.
Add the following environment block under each Trino service.
Save and close the file.
Create the Iceberg catalog configuration file.
Add the following configuration.
Save and close the file.
Validate the Docker Compose configuration.
The command returns no output if the configuration is valid.
Recreate the coordinator and workers to apply the environment variables and load the Iceberg catalog.
Check the container status.
The output displays all Trino containers with an Up status.
List the available catalogs.
The output lists the iceberg and system catalogs. If the output shows "Trino server is still initializing", wait a few seconds and run the command again.
Trino creates Iceberg tables through the REST catalog and stores their data and metadata files in Object Storage.
Open an interactive Trino CLI session.
Create a schema in the iceberg catalog.
Tables in this schema use subdirectories under the analytics/ prefix in the trino-warehouse bucket.
Create an Iceberg table for orders.
Insert sample orders into the table.
Query the table to verify the stored data.
The output displays the three orders with the values inserted in the previous step.
Verify the storage location of the table's data files.
The output displays Parquet file paths beginning with s3://trino-warehouse/analytics/, confirming that the queried rows reside in the configured Object Storage bucket.
Exit the Trino CLI.
The PostgreSQL connector allows Trino to query PostgreSQL tables and join them with Iceberg tables in a single SQL query.
Open the environment file.
Append the following variable. Replace POSTGRES_SOURCE_PASSWORD with a strong password for the sample PostgreSQL database.
Save and close the file.
Open the Docker Compose file.
Add the following service under the existing services block.
Append the following entry to the existing volumes block.
Add the following variable to the existing environment block of each Trino service. Keep the existing Object Storage variables.
Save and close the file.
PostgreSQL stores its database in a persistent volume. Trino connects to it through the internal Docker network using the postgres-source service name.
Validate the Docker Compose configuration.
The command returns no output if the configuration is valid.
Start the postgres-source service in detached mode.
Verify that the postgres-source container is ready.
The output shows the container in a healthy state.
Create the customers table.
The output displays CREATE TABLE.
Populate the customers table.
The output displays INSERT 0 2, confirming that PostgreSQL inserted two rows.
Create the PostgreSQL catalog configuration file.
Add the following configuration.
Save and close the file.
The shared catalog directory makes the connector configuration available to the coordinator and both workers.
Recreate the Trino containers to apply the environment variable and load the PostgreSQL catalog.
Verify that services are running.
The output displays all the containers with an Up status.
Join the Iceberg orders table with the PostgreSQL customers table.
The output displays three orders, with Alice associated with orders 1 and 3, and Bob associated with order 2. The query combines data from PostgreSQL and Object Storage through their respective catalogs. If the output shows "Trino server is still initializing", wait a few seconds and run the command again.
Password authentication restricts access to users defined in the password file, while HTTPS protects client connections. Resource groups control how many queries can run concurrently and how many can wait in a queue.
Generate a shared secret for internal node authentication.
Copy the generated value for a later step.
Open the environment file.
Append the following variables.
Replace:
trino.example.com with your configured domain.admin@example.com with your email address for certificate notifications.TRINO_INTERNAL_SECRET with the secret generated earlier.Save and close the file.
Allow HTTP and HTTPS connections through the firewall. Caddy uses port 80 to obtain the TLS certificate and port 443 to serve Trino.
If a cloud firewall protects the server, allow inbound TCP ports 80 and 443 in it as well.
Update the package index.
Install the password-file utility.
Create a password file for the admin user.
Enter and confirm a strong password when prompted. The command stores a bcrypt hash rather than the plaintext password.
Create the password authenticator configuration file.
Add the following configuration.
Save and close the file.
Open the coordinator configuration file.
Append the following settings.
Save and close the file.
The forwarded-header setting allows Trino to recognize HTTPS connections terminated by Caddy.
Open the first worker's configuration file.
Append the following setting.
Save and close the file.
Copy the updated worker configuration to the second worker.
Both workers use the same server configuration. Their separate node.properties files retain their unique node IDs.
Create the Caddy configuration file.
Add the following configuration.
Save and close the file.
Open the Docker Compose file.
Add the following service under the existing services: block, at the same indentation as the Trino services.
Append the following entries to the existing volumes block.
Add the following variable to the existing environment block of each Trino service. Keep the existing variables.
Save and close the file.
All three nodes receive the same shared secret. Caddy stores its certificates and configuration state in persistent volumes.
Create the resource group manager configuration file on the coordinator.
Add the following configuration.
Save and close the file.
Create the resource group definition file.
Add the following configuration.
Save and close the file.
The selector assigns all queries to global. The group allows up to four running queries and ten queued queries. Trino rejects additional queries when the queue is full. The soft memory limit queues new queries when the group exceeds 80 percent of the cluster's query memory.
Validate the Docker Compose configuration.
The command returns no output if the configuration is valid.
Recreate the Trino containers and start Caddy.
Verify that services are running.
The output displays all the containers with an Up status.
After you enable password authentication, Trino rejects the earlier --server http://localhost:8080 CLI commands with Authentication over HTTP is not enabled. Connect through the HTTPS endpoint, as the following steps do.
Verify that the query endpoint rejects requests without credentials. Replace trino.example.com with your configured domain.
The output displays 401, confirming that the HTTPS endpoint requires authentication.
Verify that Trino assigns queries to the configured resource group. Replace trino.example.com with your configured domain.
The command prompts for the administrator password. Enter it to run the query. The output displays "[global]".
Verify query execution independently of Object Storage, confirm node registration, and review completed queries in the Trino Web UI.
Run a query that does not access external data sources. Replace trino.example.com with your configured domain.
The command prompts for the administrator password. Enter it to run the query. The query returns 1, confirming that Trino can execute a query without reading from Object Storage or PostgreSQL.
Verify that the coordinator and both workers are active. Replace trino.example.com with your configured domain.
The command prompts for the administrator password. Enter it to run the query. The output displays coordinator, worker-1, and worker-2, each running version 483 with an active state.
Open https://trino.example.com in a web browser. Replace trino.example.com with your configured domain.
Log in with the username admin and the password created earlier. Verify that Active workers show 2.
Under Query details, select FINISHED from the State dropdown. Verify that the SELECT 1 query and the node-registration query appear with a FINISHED state.
Click the query ID above a completed query's entry to open its details.
On the Overview tab, verify that the query state is FINISHED and the Resource group is global. Review the session information and execution statistics.
Amazon Athena resolves tables through the AWS Glue Data Catalog, reads data from Amazon S3, and enforces access with AWS IAM and Lake Formation. This deployment replaces those layers with an Iceberg REST catalog, Vultr Object Storage, and Trino authorization rules. Migrating involves updating SQL queries and clients, transferring catalog definitions and data, and recreating access policies. Because Athena and Trino handle cost, scaling, and result caching differently, review the operational differences before switching workloads.
Athena SQL engine version 3 builds on Trino, so most standard SQL queries carry over with few changes. AWS does not publish a fixed upstream Trino version that matches engine version 3. Test queries against Trino 483, particularly date and timestamp functions, type conversions, and AWS-specific statements.
iceberg.analytics.orders.Refer to the Athena engine version 3 documentation when reviewing engine-specific behavior.
Export table definitions from AWS Glue using aws glue get-tables --database-name <database>. The command returns tables for a single database, so run it for each database you plan to migrate. Record each table's columns, partition configuration, storage location, and format. Use these definitions to recreate the corresponding schemas and tables in the Iceberg REST catalog.
Existing tables require different migration paths:
system.register_table procedure, which requires iceberg.register-table-procedure.enabled=true in the Iceberg catalog configuration. Refer to the Iceberg connector documentation for registration options.Registering a table makes its existing metadata available to the catalog. It does not copy data or convert the table format.
Copy data from Amazon S3 to Object Storage using a tool that supports separate source and destination endpoints, such as rclone. Preserve object prefixes and partition layouts during the transfer.
Iceberg metadata and manifest files can contain absolute paths to data files. Copying a table to a different bucket or prefix does not update those references. Use an Iceberg-aware relocation tool or rewrite the table into the destination location before registering it. Changing only the catalog's warehouse location does not relocate existing tables.
Pause source writes or use a consistent snapshot during the final transfer. Compare row counts and representative query results between Athena and Trino before switching clients. Include partition-level counts and aggregates such as total order amounts when validating larger tables.
AWS IAM and Lake Formation permissions do not carry over to this deployment. Lake Formation row and column access policies have no drop-in replacement, so recreate and test them using Trino authorization rules.
Password authentication identifies users, and resource groups limit query resources. Neither replaces table authorization. Test permitted and denied operations for each user before granting access to migrated data.
You have deployed Trino on a single Linux server using Docker Compose as a self-hosted alternative to Amazon Athena. The deployment includes a coordinator and two workers, an Iceberg REST catalog backed by Object Storage, federated PostgreSQL queries, HTTPS with password authentication, and resource groups. For additional connectors and configuration options, refer to the official Trino documentation.
0 Comments
Be the first to comment and share your perspective with the community.