S3 bucket versioning needs review

S3 Versioning supports object recovery after overwrites and ordinary deletions.

Description

S3 Versioning keeps earlier versions when an object changes. It protects future changes and cannot recover content lost before it was enabled.

Potential impact

Without a retained version or separate backup, an overwrite or deletion can leave nothing to restore.

Remediation

  • Set versioning: yes on buckets that need object history. Review lifecycle expiration, storage costs and who can permanently delete a version.
  • Test recovery by copying an earlier version of a test object back to the same key. Keep a separate backup if required.

Examples

Supply policy.json and choose the bucket policy and Requester Pays setting for your workload.

Before

yaml
- name: S3 버킷 생성
  amazon.aws.s3_bucket:
    name: mys3bucket
    policy: "{{ lookup('file','policy.json') }}"
    requester_pays: yes
    versioning: no

On a previously versioned bucket, versioning: no suspends versioning and leaves existing versions in place. The bucket cannot return to its original unversioned state.

After

yaml
- name: S3 버킷 생성
  amazon.aws.s3_bucket:
    name: mys3bucket
    policy: "{{ lookup('file','policy.json') }}"
    requester_pays: yes
    versioning: yes

With versioning: yes, deleting an object without its version ID creates a delete marker. Earlier versions remain until they expire or are permanently deleted.

References