Versioning, MFA Delete, and Replication
Enable versioning to protect against accidental deletion, configure cross-region replication, and add MFA Delete.
Versioning, MFA Delete, and Replication is a free AWS Solutions Architect lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the AWS Solutions Architect learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
S3 Versioning: Why It Matters
S3 Versioning enables you to preserve, retrieve, and restore every version of every object stored in a bucket. When versioning is enabled, each PUT creates a new version with a unique version ID; the old version is retained, not overwritten. If an object is deleted, S3 adds a delete marker as the current version but keeps all previous versions. This protects against accidental overwrites, accidental deletions, and unintended application-level data corruption—the most common data loss scenarios in production.
# Enable versioning on a bucket
aws s3api put-bucket-versioning \
--bucket my-important-bucket \
--versioning-configuration Status=Enabled
# List all versions of an object
aws s3api list-object-versions \
--bucket my-important-bucket \
--prefix my-document.pdfVersioning States and Transitions
An S3 bucket can be in one of three versioning states: Unversioned (default, no version IDs), Versioning-enabled (all new objects get unique version IDs, all overwrites create new versions), or Versioning-suspended (new objects get a null version ID, but existing versions are retained). You cannot delete versioning once enabled—only suspend it. Objects created before versioning was enabled have a null version ID and are not affected until overwritten or deleted.
Restoring a Previous Version
To restore an older version of a versioned object, you have two options. Option 1: copy the older version ID back to the same key—this creates a new version that is a copy of the older content, promoting it to current. Option 2: delete the current version or delete marker to expose the previous version as current. When you 'delete' an object in a versioned bucket via the console without specifying a version ID, S3 adds a delete marker—the object looks deleted to non-versioned requests but all versions are still there.
# Restore a specific version by copying it back to the same key
aws s3api copy-object \
--bucket my-important-bucket \
--copy-source 'my-important-bucket/my-document.pdf?versionId=abc123'\
--key my-document.pdfMFA Delete: Extra Protection
MFA Delete adds a second layer of protection for versioned buckets. When enabled, permanently deleting a specific version or changing the bucket's versioning state (enabled → suspended) requires providing valid MFA credentials in the API request. This protects against: an attacker who has compromised your AWS credentials permanently deleting critical versions; accidental or automated deletion of pinned object versions; and insider threats attempting to destroy audit trails. MFA Delete can only be enabled and disabled by the root user via the CLI.
# Enable MFA Delete (must be done as root user)
aws s3api put-bucket-versioning \
--bucket my-important-bucket \
--versioning-configuration Status=Enabled,MFADelete=Enabled \
--mfa 'arn:aws:iam::123456789012:mfa/root-account-mfa-device 123456'S3 Object Lock
S3 Object Lock enforces a write-once-read-many (WORM) model for regulatory compliance. Objects locked with Object Lock cannot be deleted or overwritten for a specified retention period—even by the account root user. Two modes: Governance mode (users with special permissions can override or remove the lock), and Compliance mode (no one, not even AWS, can delete the object during the retention period—the strongest protection). Object Lock must be enabled when the bucket is created and requires versioning.
# Apply a retention rule to an object
aws s3api put-object-retention \
--bucket my-compliance-bucket \
--key audit-log-2024.csv \
--version-id abc123 \
--retention '{"Mode":"COMPLIANCE","RetainUntilDate":"2027-01-01T00:00:00Z"}'S3 Cross-Region Replication (CRR)
Cross-Region Replication (CRR) automatically replicates new objects and updates from a source bucket in one Region to a destination bucket in a different Region. Use cases: compliance (keep a copy of data in a specific country), disaster recovery (reduce RPO for critical data by maintaining a copy in a second Region), and latency reduction (serve objects from the Region closest to users). CRR requires versioning enabled on both source and destination buckets and an IAM role with the necessary replication permissions.
# Apply a replication configuration
aws s3api put-bucket-replication \
--bucket source-bucket-us-east-1 \
--replication-configuration file://replication-config.json
# Config specifies Role ARN, destination bucket ARN, and filter rulesSame-Region Replication (SRR)
Same-Region Replication (SRR) replicates objects within the same Region. Use cases: log aggregation (replicate logs from multiple source buckets into one central bucket), test environment sync (keep a copy of production data in a dev bucket within the same Region), and compliance with data sovereignty within a single country that has multiple AWS AZs. Like CRR, SRR requires versioning on both buckets and an IAM role. Only new objects created after enabling replication are automatically replicated—use S3 Batch Replication to replicate existing objects.
Replication: What Is and Is Not Replicated
S3 replication does replicate: new objects, metadata, tags, ACLs, and encryption status. By default, replication does not replicate: objects that existed before replication was enabled (use S3 Batch Replication for those), delete markers (unless you enable Delete Marker Replication), objects in Glacier (not replicatable—restore first), and replicated objects (no cascading replication between three buckets). Understanding these boundaries is important for designing complete DR strategies where historical data and deletion events also need to be replicated.
S3 Replication Time Control (RTC)
Replication Time Control (RTC) is an optional add-on for CRR that provides a Service Level Agreement: 99.99% of objects replicated within 15 minutes, with replication metrics and notifications in CloudWatch. Without RTC, replication has no time guarantee—most objects replicate quickly, but outliers can take hours. RTC is essential when your DR or compliance requirements specify a maximum Recovery Point Objective (RPO) for data in S3. It adds a per-GB replication charge in addition to the standard replication data transfer cost.
Versioning and Storage Cost Impact
Enabling versioning increases storage costs because S3 retains every version of every object until explicitly deleted. A 100 MB file that is overwritten 10 times now consumes 1,000 MB of storage. Mitigate this with lifecycle rules that automatically expire non-current versions after a set number of days (e.g., delete non-current versions older than 30 days), or transition non-current versions to cheaper storage classes like Glacier. Always pair versioning with lifecycle rules to control storage costs in production.
# Lifecycle rule to expire non-current versions after 30 days
aws s3api put-bucket-lifecycle-configuration \
--bucket my-important-bucket \
--lifecycle-configuration '{"Rules":[{"ID":"expire-old-versions","Status":"Enabled","NoncurrentVersionExpiration":{"NoncurrentDays":30}}]}'Protecting Against Ransomware
S3 versioning combined with Object Lock (Compliance mode) provides strong protection against ransomware. If an attacker encrypts or deletes your objects, versioning ensures previous versions are retained (unless the attacker permanently deletes them—which is why Object Lock prevents permanent deletion during the retention period). For maximum protection: enable versioning, enable MFA Delete, apply Object Lock in Compliance mode for critical data, and replicate to a second Region with separate IAM credentials to eliminate any single-account compromise from destroying all copies.
Quick Check
Test your understanding of AWS Solutions Architect (SAA-C03) concepts from this lesson.
Lesson Recap
In this lesson you learned: versioning preserves all versions of every object and protects against accidental deletion, MFA Delete and Object Lock provide additional immutability for compliance and ransomware protection, and CRR and SRR replicate objects to other buckets to meet DR and compliance requirements. Next up we explore S3 storage classes and lifecycle policies for cost optimisation.
Frequently asked questions
Is the “Versioning, MFA Delete, and Replication” lesson free?
Yes — the full text of “Versioning, MFA Delete, and Replication” is free to read here on the web, and the AWS Solutions Architect course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the AWS Solutions Architect course, upgrade to CoddyKit PRO.
What will I learn in “Versioning, MFA Delete, and Replication”?
Enable versioning to protect against accidental deletion, configure cross-region replication, and add MFA Delete. You practise AWS Solutions Architect with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start AWS Solutions Architect?
No prior experience is required. AWS Solutions Architect on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Versioning, MFA Delete, and Replication” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this AWS Solutions Architect lesson?
Yes. Every AWS Solutions Architect lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Buckets, Objects, and Regions
- S3 Access Control: Bucket Policies and ACLs
- Versioning, MFA Delete, and Replication
- Storage Classes and Lifecycle Policies