Analyzing Medplum load balancer logs with AWS Athena

Query Application Load Balancer access logs for a self-hosted Medplum on AWS in Athena, filter by client IP, verb or status code, and keep scan costs low with date bounds.

On this page

Why teams query Medplum load balancer logs with Athena

When a self-hosted Medplum on AWS shows a traffic spike, a burst of 5xx responses or a client that behaves strangely, the application logs alone often cannot say which callers, paths and status codes were involved. Application Load Balancer access logs record each request that reaches the load balancer in front of the Medplum servers, and they are written to an S3 bucket you choose. Amazon Athena can run SQL over those files without loading them into a database, which lets an on-call engineer answer questions such as which client IP addresses generated the most requests, which HTTP verbs dominated during an incident window, or which paths returned 503 responses. Medplum's AWS Athena guide describes this path for Application Load Balancer logs stored in S3.

Athena bills by the amount of data each query scans, and the Medplum guide notes a charge of $5.00 per TB scanned. Log buckets grow quickly, so a query without bounds can read far more data than the question needs. The guide recommends always including date and time bounds, which limits the scan to the relevant log partitions and keeps the cost of each query predictable. Before the first production query, confirm the log bucket layout, the partition scheme you will use, the account that will run queries, and who may read the results, since access logs contain client IP addresses and request paths that your privacy and compliance teams will want to govern.

This section explains why the approach is useful and what it costs to run, not how to set it up. It does not cover enabling logging on the load balancer, creating the Athena table definition, writing individual filter queries, retention rules for the log bucket, or how to interpret Medplum application errors once you have identified a problem. Those steps are covered in the sections that follow and in Medplum's own documentation.

Enabling ALB access logs for the Medplum stack

This sequence turns on access logging for the load balancer in front of a self-hosted Medplum deployment and confirms that log objects arrive in S3 in a form Athena can query. It gives you a verified log source before any table or query is built.

  1. Confirm the load balancer and account

    Identify the Application Load Balancer that fronts your Medplum application servers, along with the AWS account and Region it runs in. Your platform or cloud team owns this step. Record the load balancer name, its Region and the environment it serves, so later steps refer to the correct resource. You know it is done when you can list the load balancer's listeners and target group, and those match the Medplum server endpoint you expect.

  2. Choose the S3 bucket and prefix

    Pick a dedicated S3 bucket for ALB access logs, separate from Medplum binary storage and backups, and choose a prefix such as one per environment. Create the bucket in the same Region as the Athena workgroup you plan to use, because Athena queries S3 data in its own Region. Confirm the bucket blocks public access and restricts who can read or delete objects. Done means the bucket and prefix are recorded in your configuration and the bucket is empty and locked down.

  3. Apply the bucket policy for log delivery

    Add a bucket policy that lets the regional Elastic Load Balancing log delivery principal write objects under your prefix, as described in the AWS documentation for ALB access logs. Current principal names and whether a service principal is used differ by Region and AWS account age, so confirm them in the AWS console or your CDK construct before applying. Limit the grant to your bucket and prefix. Done means the policy validates and the load balancer accepts the bucket during configuration.

  4. Enable access logging on the load balancer

    Turn on access logs in the load balancer attributes, pointing at the bucket and prefix chosen earlier. If the stack is defined with AWS CDK, set the access log option in the load balancer construct so the change is reviewed in code rather than made by hand. Confirm the exact property names and console options in your own account and CDK version. Done means the load balancer attributes show logging enabled with the expected bucket and prefix.

  5. Set retention on the log bucket

    Decide how long raw ALB logs stay in S3 and set a lifecycle rule on the bucket to expire or transition objects after that period. Retention should match your internal log retention policy and any compliance obligations your organization has for access records, which your compliance lead should confirm. Lifecycle rules also control storage cost over time. Done means a lifecycle rule is in place, visible in the bucket configuration, and scoped to the log prefix.

  6. Generate traffic and confirm log objects

    Send a few test requests through the load balancer, such as a Medplum healthcheck or a read against a non-production project. ALB publishes log files in batches at intervals, so new objects can take a while to appear. Check the bucket under your prefix for gzipped log objects, and note the path structure that includes account, Region and date. Done means at least one object with the expected name pattern is present, and you can download and open it.

  7. Record the S3 location for Athena

    Write down the exact S3 path that holds the logs, including the account, Region and date folder layout, because the Athena table location and partition scheme depend on it. Store this in your runbook alongside the bucket name, Region and lifecycle rule. Done means a teammate can locate the logs from the runbook alone, and the location matches the Athena guide you will follow next.

How ALB logs reach Athena

The path starts with clients sending requests to the Application Load Balancer in front of the self-hosted Medplum server. The load balancer writes access logs to an S3 bucket, organized by prefix and date. An Athena table, defined over that prefix, reads those files, and an analyst runs queries inside an Athena workgroup. Check that the table points at the exact prefix you enabled, that the bucket and workgroup sit inside your trust boundary, and that every query carries date and time bounds.

Log files move from the load balancer to S3, then to Athena under bounded queries.

Creating the Athena table and partitions

The Athena table is the part of this setup that decides what you can ask of the logs and what each query costs, so design it before you run anything else. An ALB writes access logs to S3 as space-delimited records, one line per request, and the table definition in Athena must map each column to that exact layout, including the field order, the timestamp format and the quoted fields such as the user agent and the TLS details. Medplum's AWS Athena guide is the starting point for the DDL and the S3 location. Treat it as a template, not a finished answer. Before you run it, compare every column against the access log format that AWS currently documents for Application Load Balancers, and confirm the S3 prefix matches the bucket and account path your load balancer actually writes to. A column that is off by one will not fail loudly; it will return plausible but wrong values.

Partitioning is what keeps scans small. Athena bills on the bytes it reads, so a table with no partition forces every query to read every log file the load balancer has ever written. Either register partitions by date (for example, one per day, with the S3 prefix encoded in the partition key) or use partition projection, which lets Athena compute partition locations from a range you declare in the table properties. Projection avoids running partition maintenance jobs but needs the date range, format and storage template set correctly, so test it with a single day before relying on it. Whichever method you choose, confirm that a query with a date bound reads only the expected prefix by checking the scanned bytes in the query results.

Naming is a small decision that prevents real confusion later. Agree on one database name, one table name and one Athena workgroup for the Medplum load balancer logs, and write them into your runbook and infrastructure code so every engineer and every automated report uses the same objects. Set the workgroup's query results location and any per-query data scan limits deliberately, since those settings control where results land and how much a single mistake can cost. If the team later adds a second load balancer or a new environment, extend the naming pattern rather than inventing a fresh one, so that saved queries and dashboards continue to point at the right table.

Query patterns and when each fits

This table compares four common Athena query shapes for Medplum load balancer logs: client IP, verb and path, status code, and hourly summaries. Read each row for the question it answers, the bounds it needs, and the trade-off between row-level detail and scan cost. The main takeaway is that every shape should carry a date and time bound before it runs.

Query shapeQuestion it answersBounds it needsTrade-off
Client IP for a suspicious sourceWhat did one source address request, and when, and with which status codes?Narrow date and hour range around the event, plus the client IP fieldReturns full request detail for one source, so results are precise but the scan still covers every log file in the window
HTTP verb and path prefix for a FHIR endpointHow often were writes or searches sent to a given FHIR resource path?Date and time bounds, the request verb and a path prefix such as the FHIR base pathUseful for traffic shape on one endpoint, but path matching on raw URLs can miss variants unless you test the prefix against sample rows
4xx or 5xx status code for error burstsWhen did errors cluster, and which paths produced them?Date and time bounds around the burst window, plus the status code fieldShows where failures concentrate, but client errors such as 401 or 429 can be noisy, so group by path before reading raw rows
Summary counts by hourHow does total request volume and error count change across each hour?Date bounds covering the period under review, grouped by hourCheapest for trend questions because output is small, but it hides which client or path caused a change
Unbounded query across all logsNot recommended as a first step for any questionNone, so the query scans the full log historyScan cost grows with retained log volume, and Athena charges $5.00 per TB scanned (Medplum AWS Athena guide)

Keeping Athena scan costs low with date bounds

Athena bills by the amount of data each query scans, not by the number of rows it returns, so the main cost control is limiting what a query reads. Athena charges $5.00 per TB scanned, and Medplum's AWS Athena guide recommends always setting date and time bounds on ALB log queries so that each query stays within the 10 MB minimum billing unit for small scans. The practical habit is simple: every query on the load balancer table should name a start and end time, and those bounds should match the partition columns the table was created with. If the table is partitioned by date, a bound in the WHERE clause lets Athena skip whole S3 prefixes. If it is not partitioned, the same bound still filters rows, but Athena has already read the files, so the saving is smaller. Confirm the partition layout in your CREATE EXTERNAL TABLE statement before relying on this.

A SELECT * over an unbounded prefix is the most expensive pattern. It reads every column of every object under the bucket path, including columns you never use, and it runs against weeks of logs. Select only the fields the question needs, such as client_ip, request_verb, elb_status_code and time, and keep the date filter in the same statement. Before running a broad query, estimate the scan. The Athena console reports the data scanned after a run, so start with a narrow one-day window, read that figure, and widen the window only as far as the investigation needs. You can also compare the size of the S3 prefix you intend to read with aws s3 ls --summarize --recursive on that path. Log volume varies with traffic, retention and the access log settings you chose, so measure your own volume rather than assuming a size. Ask your AWS account owner to set a budget alert on Athena spend so that an accidental wide scan is noticed quickly.

Protecting the logs and the people who query them

ALB access logs record who called your Medplum API, from where, and along which paths, so they deserve the same care as the data they describe. The cards below cover the bucket, the Athena workgroup, the analyst roles and the audit trail that together decide who can read those logs and what they can learn from them.

Treat log contents as sensitive

ALB access logs record client IP addresses, request paths and query strings. Medplum FHIR requests can place identifiers in URLs, such as search parameters that carry a patient reference, so a log line may reveal more than network activity. Before enabling logging, decide with your privacy and compliance leads which fields are acceptable to retain, and document that decision next to the bucket configuration.

Athena guide

Lock down the log bucket

Keep the log bucket private, block public access, and grant write access only to the load balancer delivery path. Enable default encryption on the bucket and use a bucket policy that denies unencrypted or non-TLS requests. Check the policy after every stack change, since CDK or Terraform updates can reintroduce broad grants that look harmless in a diff.

Separate log storage from application data

Store ALB logs in a dedicated bucket that is not the bucket used for Medplum binary storage, backups or exports. Mixing them means an analyst who needs log access inherits access to clinical documents, and a retention rule written for logs can delete data that must be kept. Give the log bucket its own key, its own lifecycle rules and its own owner.

Scope analyst IAM to the minimum

Create a read role for analysts that can run queries in one Athena workgroup, read the log prefix in S3, and write results only to a results location they own. Deny access to the application database, secrets and bucket administration. If an analyst also needs the logs of a non-production environment, grant that as a separate role instead of widening the production one.

Athena setup

Control query cost and exposure together

Queries that scan whole buckets cost more and widen the set of records each analyst touches. Require date and time bounds in saved queries, and set a per-query data scan limit in the workgroup if your AWS account supports it. Athena charges $5.00 per TB scanned, as stated in Medplum's Athena guide, so bounded queries also keep the exposure small.

Record who ran which query

Enable AWS CloudTrail data events for the log bucket and keep Athena query history on, so you can answer which principal ran which query and when. Confirm with your security team how long these records are retained and who can read them. Audit records about log access are themselves sensitive, so restrict them to a small group, separate from the analysts they monitor.

How long and how much effort does Athena log analysis take?

How much does it cost to query Medplum load balancer logs in Athena?

Athena bills by the amount of data each query scans, and the published rate is $5.00 per TB scanned, according to Medplum's AWS Athena guide. Each query has a 10 MB minimum charge, so very small scans still cost a little. Your bill also includes S3 storage for the logs and any log delivery charges, which AWS prices separately. Confirm current Athena, S3 and region pricing in your own AWS account before you budget, because rates and minimums can change.

What makes Athena log query costs go up?

Cost follows the data scanned, so three things matter most:

  • Log volume: a busy Application Load Balancer writes more files each day, and every unbounded query reads more of them.
  • Query frequency: dashboards or scheduled queries that rerun over the full history multiply the scan.
  • Unbounded scans: a query without date and time bounds reads every log file in the location.

Always filter on date and time partitions first, and keep the log prefix narrow. Ask whoever sets up the table to show you the partition layout before you give anyone query access.

How long does it take to enable ALB logs and build the Athena table?

For a team already working in AWS, enabling access logs and creating a first table is usually a short, bounded task, but the exact time depends on bucket policy, IAM roles, partition handling and how many people need access. No duration figure is supplied for this work, so ask your implementer or internal team to estimate it against your account setup. Plan separate time for testing a few known requests and for documenting the queries your responders will reuse.

Can our own team set up Athena log analysis without a partner?

Yes, if someone on your team can work with AWS networking, S3 and IAM, and can write and test SQL against a load balancer log format. The work is mostly configuration and query design rather than new software. The risk is in the details: bucket permissions, log retention, partition projection and access controls on the log data, which contains client IP addresses and request paths. Check these items with your AWS and security owners before you rely on the setup during an incident.

What does our team need to provide for this work?

Plan to provide four things:

  • AWS account access with rights to change load balancer logging, S3 buckets and Athena settings.
  • Ownership of the log bucket, its encryption settings and its lifecycle rules.
  • IAM roles or groups that define who can run queries and who can read results.
  • A named query owner who keeps the saved queries, reviews scan costs and answers questions from responders.

Confirm with your security team whether log data needs an approval step before analysts can query it.

Does log analysis need a designated query owner?

A designated owner is worth having because cost and access both depend on how queries are written and who can run them. The owner keeps the table definition current, maintains a small set of bounded saved queries for common needs such as filtering by IP, HTTP verb or status code, and watches monthly spend. Without an owner, ad hoc queries tend to drift toward full scans. Assign the role before go-live, not after the first surprise bill.

When is it worth bringing in a partner for Medplum log analysis?

A partner is worth considering when the logs feed incident response, audit evidence or a compliance review, and your team lacks AWS or query skills to build and test the setup. DeployOpen implements self-hosted open-source platforms in your own AWS accounts, and can plan the log setup as part of a fixed-scope engagement with the scope and deliverables agreed in writing before work starts. Ask for a written quote based on your account structure, log volume and access requirements. DeployOpen does not publish prices.

When Athena is the wrong tool for Medplum traffic

Athena answers questions about logs that already exist, but it does not tell you about a problem while it is happening. Load balancer logs land in S3 in batches, and each query scans the files you point it at, so the table is well suited to ad hoc investigation: who called a Medplum endpoint last Tuesday, which client IP produced a burst of 4xx responses, or whether a deployment changed the status code mix. It is a poor fit for live alerting, dashboards that refresh every minute, or paging an on-call engineer. Those jobs belong in a monitoring stack that reads metrics from the load balancer, the Medplum containers, PostgreSQL and Redis, and that evaluates alert rules continuously. Confirm with your AWS account team and your monitoring vendor how current the load balancer metrics are in your region before you set alert thresholds.

Treat Athena and monitoring as complements. Use the monitoring stack to decide that something is wrong, then use Athena to scope it with date and time bounds. Two sibling topics cover the parts this page does not: the metrics and alerts to watch for a self-hosted Medplum, and the request rate limits and FHIR quotas that decide how many requests a client may make before receiving a 429 response. Those controls shape the traffic you will later query, so review them before you write detection queries that assume a particular request pattern. Keep the investigation focused on one bounded window at a time, and record which queries your on-call team relies on so they can be rerun without rebuilding them under pressure.

How DeployOpen scopes and delivers Medplum log analysis

DeployOpen plans, builds and documents log analysis for a self-hosted Medplum deployment inside your own AWS account. We start from the questions your team needs answered from load balancer logs, then build and hand over the Athena setup that answers them with bounded query costs.

How we scope

  • Confirm which Medplum endpoints, load balancers and AWS accounts the log analysis covers.
  • Agree the questions to answer, such as client IPs, HTTP verbs or status code trends.
  • Agree in writing the deliverables, timeline and retention approach before any work starts.

How we build

  • Enable access logging on the load balancer and confirm log delivery to the chosen S3 bucket.
  • Create the Athena table and saved queries, with date and time bounds built into each one.
  • Test each query against sample traffic and check that results match the load balancer log format.

How we hand over

  • Document the table definition, bucket layout, query library and expected per-query scan behavior.
  • Walk your operations and security team through filtering by IP, verb and status code.
  • Record the access permissions, encryption settings and log retention rules that apply to the bucket.

How we support

  • Offer ongoing support as a retainer for query updates when the Medplum deployment changes.
  • Review query cost and scan volume with your team during routine operations reviews.
  • Update the Athena table when load balancer log fields or your deployment layout change.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.