VPS Snaps

How to set up an AWS S3 bucket for backups: settings, IAM policy and cost

To set up an AWS S3 bucket for backups, create a private bucket in a Region away from your servers, keep Block Public Access and SSE-S3 encryption on, turn on versioning, give each server an IAM identity that can upload but not delete, and add a lifecycle rule that expires old backups. As of November 2026, S3 Standard costs $0.023 per GB-month in US East (N. Virginia), according to the AWS Price List API, so 100 GB of backups costs $2.30 a month before requests and downloads. The steps below do all of this in the console and with the AWS CLI, then upload a backup and prove it restores.

The settings a backup bucket needs

A backup bucket needs nine settings, and four of them are already on in a new bucket. Check each one against this table:

SettingValue for backupsWhy
RegionNot the one your servers run inOne Region's outage can't take the servers and their backups together.
Block Public AccessAll four settings on (the default)Nothing in the bucket can be made public by mistake.
Object OwnershipBucket owner enforced (the default)ACLs are off, so IAM and bucket policies alone decide access.
Default encryptionSSE-S3 (the default, no charge)Every upload is encrypted at rest. SSE-KMS adds KMS charges.
VersioningEnabledAn overwrite or delete keeps the old backup as a noncurrent version.
Lifecycle ruleExpire backups, old versions and unfinished uploadsStorage stops growing without a cleanup script.
Server accessOne IAM user or role per server, upload without deleteA compromised server can't erase its own backups.
Storage classStandard under 30 days, Standard-IA or Glacier Instant Retrieval for longerMinimum storage durations bill early deletes.
Object LockOptional: governance mode, a short default retentionLocked versions can't be deleted until their date, even with a stolen key.

Create the bucket

Create one bucket with one prefix per server, such as web-01/, because a bucket's name and Region can't be changed later.

  1. Open the S3 console and choose the Region in the navigation bar, ideally one where your servers don't run.
  2. Choose General purpose buckets, then Create bucket.
  3. Enter a Bucket name: 3 to 63 lowercase letters, numbers and hyphens, starting and ending with a letter or number. Periods are allowed, but AWS recommends avoiding them. The name shows in object URLs, so keep it free of anything sensitive.
  4. Under Object Ownership, keep Bucket owner enforced.
  5. Under Block Public Access settings for this bucket, keep all four settings on.
  6. Under Bucket Versioning, choose Enable.
  7. Under Default encryption, keep SSE-S3.
  8. Leave Object Lock under Advanced settings off unless you have read the Object Lock section below. Once on, it can't be turned off.
  9. Choose Create bucket.

The same bucket from the CLI, run with admin credentials:

Terminal
aws s3api create-bucket --bucket acme-server-backups --region eu-central-1 --create-bucket-configuration LocationConstraint=eu-central-1
  • --region and LocationConstraint must name the same Region. For us-east-1, drop --create-bucket-configuration; every other Region needs it.
  • New buckets get Block Public Access, disabled ACLs and SSE-S3 without extra flags.

Turn on versioning, then confirm that Block Public Access and encryption are in place:

Terminal
aws s3api put-bucket-versioning --bucket acme-server-backups --versioning-configuration Status=Enabled
Terminal
aws s3api get-public-access-block --bucket acme-server-backups
aws s3api get-bucket-encryption --bucket acme-server-backups

The first check should show BlockPublicAcls, IgnorePublicAcls, BlockPublicPolicy and RestrictPublicBuckets all true, and the second "SSEAlgorithm": "AES256", which is SSE-S3. If an older bucket shows any of the four as false, turn them all on:

Terminal
aws s3api put-public-access-block --bucket acme-server-backups --public-access-block-configuration BlockPublicAcls=true,IgnorePublicAcls=true,BlockPublicPolicy=true,RestrictPublicBuckets=true

AWS recommends waiting 15 minutes after first enabling versioning before writing objects.

Give the server an IAM policy that can upload but not delete

A backup server needs s3:PutObject on its own prefix and nothing that deletes, so that whoever takes over the server can't erase its backups. Never put root or admin keys on a server. On EC2, attach an IAM role through an instance profile, and programs on it get temporary credentials. Elsewhere, use an IAM user with an access key, or IAM Roles Anywhere, which AWS suggests for machines outside AWS. Either way, attach this policy:

backup-policy.json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "ListOwnPrefix",
      "Effect": "Allow",
      "Action": "s3:ListBucket",
      "Resource": "arn:aws:s3:::acme-server-backups",
      "Condition": { "StringLike": { "s3:prefix": ["web-01/*"] } }
    },
    {
      "Sid": "UploadAndReadOwnPrefix",
      "Effect": "Allow",
      "Action": [
        "s3:PutObject",
        "s3:GetObject",
        "s3:AbortMultipartUpload"
      ],
      "Resource": "arn:aws:s3:::acme-server-backups/web-01/*"
    }
  ]
}
  • s3:ListBucket is a bucket action, so its Resource is the bucket ARN without /*. The s3:prefix condition allows listings under web-01/ only, which is what aws s3 ls and aws s3 sync request for that path.
  • s3:PutObject uploads, including each part of a multipart upload. s3:GetObject downloads, for restores and checks. s3:AbortMultipartUpload lets the CLI clean up a failed large upload.
  • There is no s3:DeleteObject or s3:DeleteObjectVersion, so this key can't delete backups. Lifecycle rules do the pruning instead.
  • Without versioning, s3:PutObject can still replace a backup by uploading to the same key. With versioning on, that upload only adds a new version and the old one stays.
  • Tools that prune their own repository or remove their own lock files, such as restic, need s3:DeleteObject as well. In a versioned bucket that delete only adds a delete marker, because the policy still doesn't grant s3:DeleteObjectVersion.

Create the user, attach the policy and make an access key with admin credentials. The console route is IAM, Users, Create user without console access, then Add permissions, and Create access key on the user's Security credentials tab. From the CLI:

Terminal
aws iam create-user --user-name backup-web-01
aws iam put-user-policy --user-name backup-web-01 --policy-name s3-backup-web-01 --policy-document file://backup-policy.json
aws iam create-access-key --user-name backup-web-01

Then, on the server, save the key under its own profile:

Terminal
aws configure --profile backups

The secret access key is shown once, and the CLI stores it in plain text in ~/.aws/credentials. Keep that file readable only by the user that runs backups, with chmod 600. Give each server its own user and prefix, so one leaked key reaches one server's backups.

Versioning: what it protects

Versioning keeps every overwritten or deleted backup as a noncurrent version, so a buggy script or a stolen key can hide backups but not destroy them. A delete without a version ID only adds a delete marker, and only s3:DeleteObjectVersion, which the policy above leaves out, removes a version for good. Each version is billed as a full object, and versioning can later be suspended but never removed, so pair it with the noncurrent-version rule below.

Expire old backups with a lifecycle rule

A lifecycle rule deletes backups after a set number of days, so the bucket stops growing and the backup key never needs delete rights. This rule keeps 30 days of backups:

lifecycle.json
{
  "Rules": [
    {
      "ID": "expire-server-backups",
      "Filter": { "Prefix": "" },
      "Status": "Enabled",
      "Expiration": { "Days": 30 },
      "NoncurrentVersionExpiration": { "NoncurrentDays": 7 },
      "AbortIncompleteMultipartUpload": { "DaysAfterInitiation": 7 }
    }
  ]
}
  • "Prefix": "" applies the rule to the whole bucket. Use web-01/ to target one server.
  • Expiration Days: 30: in a versioned bucket, S3 adds a delete marker 30 days after upload, and the backup becomes noncurrent.
  • NoncurrentVersionExpiration NoncurrentDays: 7: permanently deletes a version 7 days after it became noncurrent. A backup lives about 37 days, and an accidental delete can be undone for 7. Add NewerNoncurrentVersions (1 to 100) to also keep that many newer old versions.
  • AbortIncompleteMultipartUpload: removes the parts of uploads that never finished. You pay for those parts until they go.
  • With Days set, S3 also removes leftover delete markers on its own.
Terminal
aws s3api put-bucket-lifecycle-configuration --bucket acme-server-backups --lifecycle-configuration file://lifecycle.json

To keep monthly backups for a year at a lower price, upload them under their own prefix and move them to Glacier Instant Retrieval after 30 days. Rules whose prefixes overlap would apply the shortest expiration to both, so keep daily and monthly copies apart:

lifecycle.json
{
  "Rules": [
    {
      "ID": "web-01-daily",
      "Filter": { "Prefix": "web-01/daily/" },
      "Status": "Enabled",
      "Expiration": { "Days": 30 },
      "NoncurrentVersionExpiration": { "NoncurrentDays": 7 },
      "AbortIncompleteMultipartUpload": { "DaysAfterInitiation": 7 }
    },
    {
      "ID": "web-01-monthly",
      "Filter": { "Prefix": "web-01/monthly/" },
      "Status": "Enabled",
      "Transitions": [{ "Days": 30, "StorageClass": "GLACIER_IR" }],
      "Expiration": { "Days": 365 },
      "NoncurrentVersionExpiration": { "NoncurrentDays": 7 },
      "AbortIncompleteMultipartUpload": { "DaysAfterInitiation": 7 }
    }
  ]
}

Each transition is a billed request: as of November 2026, moving objects to Glacier Instant Retrieval costs $0.02 per 1,000 objects in US East (N. Virginia), according to the AWS Price List API. Lifecycle doesn't transition objects under 128 KB by default, which suits backup archives.

put-bucket-lifecycle-configuration replaces the bucket's entire lifecycle configuration, so the file must contain every rule you want. Rules also apply to objects already in the bucket: a new 30-day rule queues everything older than 30 days for removal.

Removal is asynchronous, but storage isn't billed after the expiration date. Run this with admin credentials; the backup user can't change lifecycle rules, by design.

Which storage class to use, and what it costs

Use S3 Standard for backups kept under 30 days, and Standard-IA or Glacier Instant Retrieval for copies kept longer and rarely restored. The prices below are for US East (N. Virginia) as of November 2026, from the AWS Price List API files behind the Amazon S3 pricing page; other Regions cost more or less. Minimum durations and sizes are from the S3 User Guide.

Class (API value)Storage per GB-monthMinimum durationGetting data back
S3 Standard (STANDARD)$0.023 (first 50 TB)NoneImmediate, no retrieval fee
Standard-IA (STANDARD_IA)$0.012530 days; 128 KB minimum sizeImmediate, $0.01 per GB
One Zone-IA (ONEZONE_IA)$0.0130 days; 128 KB minimum sizeImmediate, $0.01 per GB, one Availability Zone
Glacier Instant Retrieval (GLACIER_IR)$0.00490 days; 128 KB minimum sizeMilliseconds, $0.03 per GB
Glacier Flexible Retrieval (GLACIER)$0.003690 days; 40 KB metadata added per objectRestore first: minutes to hours, per-GB fee
Glacier Deep Archive (DEEP_ARCHIVE)$0.00099180 days; 40 KB metadata added per objectRestore first: hours, $0.02 per GB (standard) or $0.0025 (bulk)

Deleting an object before its minimum duration bills the rest of it, so a 7-day backup in Standard-IA is charged for 30 days. Glacier Flexible Retrieval and Deep Archive need a restore request before download, which slows a recovery. AWS recommends One Zone-IA only for data you can recreate. To upload straight into a class, add --storage-class:

Terminal
aws s3 cp web-01-2026-11-03.tar.gz s3://acme-server-backups/web-01/monthly/2026-11-03.tar.gz --storage-class STANDARD_IA --profile backups

Storage is only part of the bill. As of November 2026 in US East (N. Virginia), according to the AWS Price List API:

  • Uploads to S3 Standard cost $0.005 per 1,000 PUT, COPY, POST or LIST requests, and downloads cost $0.0004 per 1,000 GET requests. Standard-IA charges $0.01 per 1,000 PUT requests.
  • Data transferred in from the internet is free.
  • Data transferred out to the internet costs $0.09 per GB for the first 10 TB a month, after the first 100 GB a month, which is free and shared across all AWS services.
  • Every version and every unfinished multipart part counts as stored data.

For example, 200 GB of backups in S3 Standard costs $4.60 a month. Restoring all 200 GB to a server outside AWS costs $9.00 in transfer if nothing else has used the free 100 GB that month, which is why egress is the cost people forget.

Lock backups with Object Lock

Object Lock stops object versions from being deleted or overwritten until a date. It needs versioning, and you can turn it on when creating the bucket or later from the bucket's Properties tab. After that, Object Lock can't be disabled and versioning can't be suspended.

  • Governance mode: only a user with s3:BypassGovernanceRetention who sends the bypass header can delete locked versions. Enough to stop a stolen server key.
  • Compliance mode: nobody can delete a locked version or shorten its lock, root included. AWS says the only early exit is deleting the account.
  • Legal hold: a lock with no end date, removed by hand.
Terminal
aws s3api put-object-lock-configuration --bucket acme-server-backups --object-lock-configuration '{"ObjectLockEnabled": "Enabled", "Rule": {"DefaultRetention": {"Mode": "GOVERNANCE", "Days": 14}}}'

This sets a default retention, so every new version is locked for 14 days without changing your upload commands. Lifecycle rules don't remove noncurrent versions that have Object Lock applied, so keep the lock shorter than your expiration window.

Start with governance mode and a short period. A compliance-mode lock set too long can't be undone, and you pay for that storage until it ends.

Upload backups with the AWS CLI

Upload each backup with aws s3 cp under a unique, dated key, so nothing overwrites it. Make the archive first, for example with tar, then copy it:

Terminal
aws s3 cp /var/backups/web-01-2026-11-03.tar.gz s3://acme-server-backups/web-01/daily/2026-11-03.tar.gz --profile backups --only-show-errors

--only-show-errors keeps cron logs short. A single PUT tops out at 5 GB; the aws s3 commands switch to multipart for large files, up to 48.8 TiB per object. To stream an archive without a temporary file, use - as the source:

Terminal
tar -czf - /etc /var/www | aws s3 cp - s3://acme-server-backups/web-01/daily/2026-11-03-files.tar.gz --profile backups

For a stream over 50 GB, add --expected-size with the size in bytes, or the upload can fail at the 10,000-part limit. To mirror a local backup directory instead:

Terminal
aws s3 sync /var/backups/web-01/ s3://acme-server-backups/web-01/daily/ --profile backups --only-show-errors

sync copies files that are new, changed in size, or newer locally. It deletes nothing unless you add --delete; leave that off, or a wiped local directory empties the remote copy too, and the policy above would refuse it anyway. Schedule either command with cron. For database dumps, backing up a database to S3 pipes pg_dump or mysqldump straight into the bucket; for deduplicated, encrypted file backups, point restic or rclone at the same bucket.

Verify a backup

A backup is verified only when a downloaded copy matches what you uploaded and opens. Start by listing what arrived:

Terminal
aws s3 ls s3://acme-server-backups/web-01/ --recursive --human-readable --summarize --profile backups
Terminal
aws s3api head-object --bucket acme-server-backups --key web-01/daily/2026-11-03.tar.gz --checksum-mode ENABLED --profile backups

head-object returns ContentLength and, with --checksum-mode ENABLED, the stored checksum. S3 adds a CRC-64/NVME checksum when an upload doesn't specify one. Don't compare the ETag with an MD5 sum: for multipart uploads it isn't one. The real proof is a download:

Terminal
aws s3 cp s3://acme-server-backups/web-01/daily/2026-11-03.tar.gz /tmp/restore-test.tar.gz --profile backups && sha256sum /tmp/restore-test.tar.gz && tar -tzf /tmp/restore-test.tar.gz > /dev/null && echo OK

Compare the hash with one recorded before upload. To recover an overwritten or deleted backup, find it with aws s3api list-object-versions --bucket acme-server-backups --prefix web-01/ and fetch it with aws s3api get-object and --version-id. Listing versions needs s3:ListBucketVersions, so use admin credentials. More in testing a restore.

Keep a second copy outside the bucket

One bucket in one AWS account is still one copy, because an admin in that account can delete any version that isn't under a compliance-mode lock. For a copy that survives an account takeover, keep one in a separate AWS account or at a second provider, per the 3-2-1 rule; copying a bucket between providers shows how.

  • An account can create 10,000 general purpose buckets by default.
  • Multipart parts are 5 MiB to 5 GiB, with at most 10,000 parts per upload.
  • Lifecycle transitions skip objects under 128 KB by default.

For backups an attacker cannot remove, see protecting backups from ransomware; to keep what is stored readable only by you, encrypt it before upload.

Frequently asked questions

How much does it cost to store backups in Amazon S3?
As of November 2026, S3 Standard costs $0.023 per GB-month in US East (N. Virginia), so 100 GB costs $2.30 a month, and Glacier Deep Archive costs $0.00099 per GB-month, according to the AWS Price List API. Requests are extra, and downloading a restore to a server outside AWS costs $0.09 per GB after the first 100 GB a month.
Which S3 storage class is best for backups?
S3 Standard for backups kept less than 30 days, since it has no minimum duration or retrieval fee. Standard-IA for copies kept 30 days or more and rarely restored, Glacier Instant Retrieval for 90 days or more. Glacier Flexible Retrieval or Deep Archive only for archives you can wait hours to restore.
Can an IAM user upload backups to S3 without being able to delete them?
Yes. Grant s3:PutObject and leave out s3:DeleteObject and s3:DeleteObjectVersion, then turn on versioning, because without it an upload to an existing key replaces the old backup. Let a lifecycle rule do the deleting, and add Object Lock for a time-based lock on top.
Is a new S3 bucket private by default?
Yes. New buckets have all four Block Public Access settings on and ACLs disabled, so nothing is public unless you change those settings.
Do I need to turn on encryption for an S3 backup bucket?
No. Since January 5, 2023, S3 encrypts all new uploads with SSE-S3 at no additional cost. Choose SSE-KMS only if you need to control the keys, and expect KMS charges.
Is a backup bucket the same as AWS Backup for S3?
No. AWS Backup backs up data that is already in S3 buckets into a backup vault, and it requires versioning on those buckets. A backup bucket is where your servers send their own backups. You can use both.

How this was checked

Commands, limits and prices were checked against these official pages, on October 3, 2026: