Loki with Amazon S3 storage

Learn how Loki lays out chunks and TSDB indexes in S3, how to replace static keys with IAM roles, and how bucket lifecycle rules and request volume shape cost and retention.

On this page

Loki with Amazon S3 storage: when teams choose it

If your team runs self-hosted Loki in AWS and needs durable, low-cost log storage that you can access with IAM instead of long-lived credentials, Amazon S3 is the object store to plan around. Loki keeps its compressed log chunks and its TSDB index in object storage, not on the ingester or query servers, so the bucket becomes the system of record for everything you have logged. Amazon S3 is one of the object stores Grafana lists as recommended for production, alongside Google Cloud Storage and Azure Blob Storage, which makes it the default choice for most AWS-hosted clusters.

S3 fits best when your Loki components already run on AWS compute such as EC2 or EKS, when your security team expects access to be granted through IAM roles and bucket policies, and when you need retention measured in months rather than days. It is a weaker fit if your data must stay on premises, in which case the S3-compatible and filesystem options covered elsewhere in this group apply. This page walks through the bucket layout for chunks and ruler data, how to replace static keys with IAM roles, why bucket lifecycle rules must outlast Loki retention, and what drives request charges. Confirm your current region, account structure and cost model with AWS and your own environment before you size anything.

Before you commit, confirm three things: which Loki version and deployment mode you will run, since the documentation on Loki deployment modes ties storage choices to scale, and whether your data residency rules allow the AWS region you intend to use. Also confirm that your security team accepts the IAM-based access model described in the rest of this page, because the access path you approve here determines who can read, delete or replace the logs stored in the bucket.

How writes, queries, compaction and retention touch the S3 buckets

The diagram starts with distributors and ingesters, which write compressed chunks and index files to S3 under the Loki service role. Queriers read the same objects back, while the compactor rewrites the index, applies retention and processes deletes. A bucket lifecycle rule sits outside Loki as a separate control, so check that its expiry never removes data before Loki's retention has run.

Loki components reach the S3 bucket through the service role, with lifecycle rules as a separate control.

IAM roles or static keys: how to authenticate Loki to S3

An IAM role attaches permissions to the compute that runs Loki, so the Loki process receives short-lived credentials from AWS without any secret stored in its configuration files. The common patterns are an EC2 instance profile for Loki running on virtual machines, EKS Pod Identity or IAM Roles for Service Accounts (IRSA) for Loki running on Kubernetes. Credentials issued this way expire and are renewed automatically by the AWS SDK, which removes the rotation task from your operators. Access is also easier to review, because the role's policy and its trust relationship show exactly which workload may use which bucket.

  • No secret in the config: The storage_config block can omit static keys, so there is nothing to leak through Git, backups or support bundles.
  • Automatic rotation: Temporary credentials are renewed by the SDK, so rotation is handled by AWS rather than a runbook.
  • Narrow trust: The trust policy can name a specific instance profile or Kubernetes service account, limiting which workloads can assume the role.
  • Clear audit trail: CloudTrail records the assumed role session, which ties bucket access to a workload identity.
  • Blast radius limits: A compromised pod or host exposes only the session it holds, and the policy can restrict Loki to its own bucket prefixes.

Before you rely on this path, confirm with the Loki storage documentation and your Loki version which AWS credential chain it uses, and test the role on a non-production bucket.

Which S3 configuration options fit which deployment

This table compares the main S3 configuration choices for self-hosted Loki: bucket layout, authentication, encryption, addressing style and retention alignment. Read each row against your deployment mode and your security team's requirements, then confirm the exact settings in Loki's storage documentation before you build.

OptionWhen it fitsTrade-offWhat to confirm
Single bucket with prefixesSmall or single-team installs where one bucket, one policy and one set of permissions is simpler to reviewLifecycle rules and IAM policies apply to the whole bucket unless prefix conditions are written carefullyPrefix layout Loki expects for chunks and ruler data in the storage docs
Separate buckets for chunks and rulerClusters where ruler data needs different retention, access or encryption from log chunksMore buckets to create, tag, grant and monitorWhich Loki components write to each bucket and whether ruler storage is configured separately
IAM role with temporary credentialsLoki running on AWS compute such as EC2 or EKS, where the team wants no static access keys in configurationRole trust policies and session behavior must be set correctly and testedCredential chain Loki uses for S3 and the permissions required for list, get, put and delete
Static access keysAir-gapped or non-AWS hosts where no instance or workload identity is availableKeys must be stored, rotated and revoked by your team, and they are a common leak pathWhether your security policy allows long-lived keys and how rotation is handled
SSE-S3 encryptionDefault server-side encryption where AWS-managed keys meet your data protection requirementsLess key-level control and no separate key policy to reviewWhether your auditors accept AWS-managed keys for log data
SSE-KMS encryptionEnvironments that need customer-managed key policies, key rotation control or key-level audit trailsKey policy design adds work, and each KMS request is billed, which raises request cost on busy clustersKMS request pricing in current AWS documentation and key policy grants for the Loki role
Virtual-hosted addressingNative AWS S3 with standard endpoints and no custom endpoint configurationGenerally the default path for AWS, with fewer endpoint settings to get wrongBucket naming rules and region settings in your Loki storage configuration
Path-style addressingS3-compatible endpoints or private gateways that require bucket names in the URL pathNot needed for native AWS S3 and adds a setting that must match the endpointWhether the Loki release you run exposes this option and the endpoint form your gateway needs
Lifecycle rules outlasting Loki retentionAny cluster where S3 must not delete chunks before Loki's retention or compactor has runIf lifecycle expiry is shorter than Loki retention, data disappears early and queries failLifecycle expiry set longer than the longest retention period, plus verification that compactor deletes run

Setting up Loki on S3 with IAM roles

This sequence takes a self-hosted Loki from empty S3 buckets to a verified install that writes chunks and indexes with IAM role credentials, applies retention, and removes expired data on schedule. Each step closes with a check, so the platform team can confirm one layer before building the next.

  1. Create the S3 buckets and region

    Create the bucket or buckets Loki will use for chunks and, if you plan to store ruler data in object storage, a separate bucket for that data. Place them in the AWS region where your Loki workload runs, keep block public access enabled, and agree on the versioning setting with your security team before any data arrives, because versioning changes how deleted objects are kept. Check: each bucket exists in the intended region, public access is blocked, and the bucket names are recorded in your configuration plan.

  2. Write a least-privilege IAM policy

    Write an IAM policy that allows only the actions Loki needs on its own prefixes: reading, writing, listing and deleting objects in the chunks and ruler paths, plus listing the bucket restricted by prefix. Deletion is required because the compactor removes expired chunks, so leaving it out breaks retention. Scope resources to the bucket ARNs and prefix patterns, and avoid wildcards across the account. Check: a policy simulation with your IAM tooling shows the Loki actions allowed on the Loki prefixes and denied on other buckets.

  3. Attach the policy to a role

    Attach the policy to an IAM role and bind that role to the workload that runs Loki, such as an instance profile on virtual machines or a pod identity mechanism on Kubernetes. Your cloud team owns this step because it depends on how your accounts and clusters are set up, so confirm which mechanism your platform already supports before you choose. Do not create access keys for a Loki user. Check: from inside the Loki workload, the identity call returns the expected role, and no static access key is mounted into the container or set in its environment.

  4. Configure storage_config and schema_config without static keys

    In the Loki configuration, set the object store to S3 under storage_config and schema_config, providing the bucket name and region. Leave the access key fields unset so the AWS SDK picks up the role credentials, and set the TSDB index store with a schema version your Loki release supports. Confirm the exact key names in the storage documentation for your version before you deploy, and keep the configuration in version control with secrets kept out of it. Check: Loki starts, the configuration check passes, and the first object write logs no authentication errors.

  5. Set retention and lifecycle expiry in order

    Enable retention in the compactor by setting retention_enabled, then define the retention period globally or per tenant. Retention is disabled by default, so logs are kept until you turn it on. Next, set the S3 lifecycle expiry on the chunks prefix to a period longer than the Loki retention. If the lifecycle rule expires objects before the compactor removes them, S3 deletes data that Loki still indexes, and queries for that time range fail in ways that are hard to diagnose. Check: the lifecycle expiry is recorded as longer than the retention period, and compactor logs show retention enabled.

  6. Verify ingestion and query with a test write

    Send a test log line with a known label set to the Loki push endpoint, or through Grafana Alloy, then query it in Grafana or with LogQL. If auth_enabled is true, include the X-Scope-OrgID header on both the write and the query. Check: the test line returns from a query for its labels and time range, and a new object appears under the chunks prefix in the bucket.

  7. Confirm retention removes expired objects

    In a non-production environment, use a short test retention setting and a dedicated test tenant and label, so the check does not touch production data. Wait for the compactor's retention pass, then confirm that expired chunks disappear from the bucket and that queries for the removed range return no data. Confirm the compactor schedule and expected timing in the retention documentation and do not assume them. Check: an object older than the retention period is gone from S3, and the lifecycle expiry has not removed objects still inside the retention window.

Why bucket lifecycle rules must outlast Loki retention

Loki retention has to be the control that removes data, and the S3 lifecycle rule has to be a longer backstop. Loki's retention is applied by the compactor, and it is disabled by default, so logs stay in the bucket indefinitely until you set retention_enabled and define the periods you want. The compactor decides which chunks and index entries are past their retention window and deletes them. An S3 lifecycle rule works on object age alone and knows nothing about Loki's tenants, streams or index periods. If the lifecycle rule expires chunks sooner than the retention period you configured, S3 deletes objects that Loki still expects to query, and those queries return gaps with no error that points at the bucket. If the lifecycle rule is set too late, or not set at all, objects that the compactor has already dropped from the index can linger in the bucket as storage you pay for and never read.

Set Loki retention first, globally or per tenant and per stream selector, and choose the periods from your legal and operational requirements. Then add a lifecycle rule on the chunks prefix and, where you use them, the ruler prefix, with an expiration window longer than the longest retention period in the cluster. The gap between the two is a safety margin, not a second retention policy, so keep it as small as your recovery and audit needs allow. Confirm the exact prefixes, object naming and the compactor's behavior for your Loki version in the Loki retention documentation and the storage guide before you write the rule, because a wrong prefix leaves data that the rule never touches.

Verify removal rather than assuming it. After retention is enabled, check that the compactor is running and logging its retention work, query a time range that should now be outside retention and confirm it returns nothing, and then inspect the bucket to see whether objects in that range have disappeared as expected. Repeat the check after you change any retention period, since shortening a period is when lifecycle conflicts appear. Treat the lifecycle rule as something to test with a known-age object, not something you configure once and forget.

What drives S3 request and storage cost for Loki

Loki on S3 bills for three things: the requests Loki makes to the bucket, the volume of compressed data it keeps, and the traffic that leaves the bucket's region. Each card below names one driver, what sets its size, and what to check before you price the deployment.

Write requests from ingestion

Ingesters flush compressed chunks to the bucket in batches, so every flush is a PUT request. The number of writes depends on ingestion rate, stream count and how often chunks are cut, not only on the raw gigabytes received. Ask your team to estimate flush frequency from your own stream count and ingest volume, then multiply by the S3 PUT rate on the AWS pricing page for your region.

Loki storage docs

List and compaction requests

The compactor lists objects while it compacts the index, applies retention and processes deletes, and each of those passes adds LIST and GET calls. Many small index files and many small chunks raise this count. Confirm the compactor schedule and the number of tenants and periods in your schema, because both change how much listing the bucket receives every run.

Read requests from queries

Every chunk a query touches is fetched with a GET request unless a cache already holds it. Wide time ranges, broad label selectors and dashboards that refresh often produce the most reads. Caching and query sharding reduce these calls, so ask how much of your read traffic a cache will absorb before you size the request budget.

Storage volume after compression

You pay for the bytes stored after Loki compresses chunks, so the ratio of raw log volume to stored size decides the monthly storage line. Log content, label design and structured metadata all affect how well chunks compress. Measure compressed size on a representative tenant for a week, then extrapolate using the storage rate in the AWS pricing pages.

Retention length

Retention is the largest multiplier on storage, because the stored volume grows with every day you keep logs. Loki retention is disabled by default, so logs accumulate until you set it, and a bucket lifecycle rule that expires objects too early can remove data your retention settings still expect. Agree the retention period per tenant or stream with your compliance owner before you size the bucket.

Cross-region and egress traffic

Traffic between your Loki components and the bucket is free only when they share a region, and data leaving AWS or crossing regions is billed. Running ingesters, queriers or Grafana in a different region from the bucket, or reading logs from outside AWS, adds transfer charges on top of request and storage fees. Place Loki in the same region as the bucket and confirm the transfer rules on the AWS pricing page for your topology.

KMS requests under SSE-KMS

If the bucket uses SSE-KMS encryption, each object read and write also calls AWS KMS, and those calls are billed separately from S3. Loki's request volume therefore multiplies into KMS request volume, which many teams overlook in early estimates. Decide whether SSE-S3 meets your policy, or confirm the KMS request rate and any bucket key setting with your AWS account team before you commit to SSE-KMS.

Questions teams ask before storing Loki in S3

What does a Loki on S3 implementation cost and what drives the effort?

No price is published here, and DeployOpen does not publish a price list. A quote follows from a written scope. The main cost components are the engineering time to design the bucket layout, IAM roles, lifecycle rules and retention settings, the work to deploy and verify Loki against those buckets, and the handover to your team. Effort rises with the number of tenants, the number of environments, the presence of existing log pipelines that must be connected, and the compliance evidence you need. Costs that recur sit mostly on your side: S3 storage, S3 request charges, data transfer and the compute running Loki. Ask any partner for a quote that separates one-time build work from ongoing support, and that states which AWS charges remain with your account.

How long does a Loki S3 setup take?

The duration depends on factors you can list before asking for a schedule. The deployment mode you choose, whether Loki runs on Kubernetes or on servers, how many AWS accounts and buckets are involved, how many retention rules you need, and how quickly your team can approve IAM roles and network paths all change the timeline. The write-ahead log and compactor settings add work when durability and deletion requirements are strict. Ask for a timeline that lists each milestone, the approvals it depends on and the testing it includes, rather than a single number. Treat any duration without that breakdown as a starting point, not a commitment.

What must our team provide before the work starts?

Your team must provide the AWS accounts and the authority to create buckets, roles and policies in them. You also need network access between Loki and S3, including VPC endpoints or egress paths where required, and a named owner for IAM decisions. Before the build starts, decide the retention policy by tenant or stream, because it sets the bucket lifecycle rules. Provide the log sources, the identity provider for Grafana access, and the people who will review logs and approve deletions. Confirm each item in the scope document so that gaps show up before deployment rather than during it.

Can our team set up Loki on S3 by following the official docs?

Yes, a capable platform team can deploy Loki against S3 using the official documentation, and the Loki storage and retention pages describe the configuration keys involved. The harder parts are judgment calls the docs do not make for you: how to split buckets, which IAM permissions Loki needs and no more, how lifecycle rules interact with compactor retention, how to verify that data is actually removed, and how to run upgrades. Teams that have not operated object storage backed services before often underestimate the testing. Decide early whether your team has the time and skills, and whether you want an outside partner to review the design and verification steps.

How do IAM roles differ from static access keys for Loki?

With IAM roles, Loki receives temporary credentials from the environment it runs in, such as an instance profile, a Kubernetes service account mapped to an IAM role, or an equivalent AWS identity mechanism. Nothing long-lived is stored in a configuration file, and access can be scoped to the specific buckets and actions Loki needs. Static keys are long-lived secrets that must be stored, rotated and revoked by hand, and a leaked key stays valid until someone notices. Use roles where your platform supports them, restrict the policy to the chunk and ruler buckets, and confirm the exact actions with the Loki storage documentation and your own security review before deployment.

What happens to stored data when Loki retention and the S3 lifecycle rule disagree?

Loki retention is applied by the compactor and is disabled by default, so logs are kept indefinitely until retention_enabled is set. If an S3 lifecycle rule expires objects sooner than the Loki retention period, chunks disappear before Loki expects them, and queries for that time range return gaps or errors. If the lifecycle rule keeps objects longer than Loki's retention, the compactor removes index references but the objects can remain in the bucket until the lifecycle rule expires them, which keeps data longer than you intended. The safe pattern is to set the bucket lifecycle rule to outlast the longest Loki retention period, let Loki handle deletion within that window, and verify removal by querying and by inspecting the bucket. Confirm this sequence against the Loki retention documentation before you rely on it.

What drives S3 request costs for Loki?

S3 charges come from storage volume, the number and type of requests, and data transfer. Loki writes chunks and index files, reads them during queries, and the compactor lists and rewrites objects, so request volume grows with ingestion rate, query load, the number of small chunks and how often compaction and retention run. Cross-region or internet data transfer adds cost that same-region VPC access avoids. Ask for a cost estimate that uses your daily log volume, retention periods, query pattern and region, and confirm the current S3 pricing for that region with AWS. Your AWS bill will show the actual figures once Loki runs.

Where to confirm storage and retention details

Start with the Loki storage documentation for the configuration keys that connect Loki to an S3 bucket, including the storage_config and schema_config blocks and how chunks and TSDB index files are written. Check the object store section against the Loki version you plan to run, because the supported storage clients and their option names change between releases. Confirm which settings your build expects for the S3 endpoint, region and credential chain before you copy any example into production, and record the exact keys you verified in your deployment repository so later upgrades can be checked against them. The Loki storage documentation is the natural first read for this work.

The retention documentation is the reference for how the compactor removes data, and it is the one to read before you set any S3 lifecycle rule. Confirm three things there: that retention_enabled must be set explicitly because retention is off by default, which retention scopes (global, per tenant or per stream selector) your design needs, and how the compactor's run interval affects when data actually disappears. Then compare those findings with the bucket lifecycle rules you configure, so that the bucket never expires objects before Loki has finished its own retention pass. Test this on a non-production bucket with known test data.

Confirm the version you deploy against the Loki releases page on GitHub, which lists the current release and its publication date. Storage behavior, default values and deprecations can change between minor and major releases, so pin the version in your plan and check the release notes for every storage, schema or compactor change before an upgrade. Keep a short written record of the version, the documentation pages you checked and the date you checked them, because your security and compliance reviewers will ask how the configuration was validated. The Loki releases page lists the versions that are current when you read it.

How DeployOpen scopes and delivers Loki on S3

DeployOpen approaches Loki with Amazon S3 storage as a fixed-scope engagement inside your AWS accounts. The work starts with written decisions on bucket layout, IAM roles, lifecycle rules and retention, then builds, tests and documents the setup so your team can run it.

How we scope

  • Written scope names the buckets for chunks and ruler data, the AWS accounts and regions involved, and who owns each.
  • Scope records the retention periods per tenant and the lifecycle rules that must outlast them.
  • Scope states the expected request volume and cost drivers so you can review the quote against them.

How we build

  • Loki is configured to use IAM roles for S3 access, with no static access keys stored in configuration files.
  • Bucket policies, encryption and lifecycle rules are applied and checked against the retention settings in Loki.
  • Retention is tested end to end so you can confirm that expired data is actually removed from the bucket.

How we hand over

  • Handover includes the written configuration, IAM policy documents and a record of each design decision.
  • Runbooks explain how to verify retention, review S3 request metrics and rotate or adjust access.
  • Your team receives a walkthrough of the deployment so operators can run and change it without us.

How we support

  • Ongoing support, Loki upgrades and continuous testing are available as a retainer after handover.
  • Upgrades are planned against the Loki release notes and checked against your bucket and IAM setup.
  • Changes to retention, lifecycle rules or bucket layout go through the same written scope and review.

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.