Recover an Overwritten Portfolio Asset

AWSBeginner
Practice Now

Introduction

Recover an overwritten portfolio cover with S3 versions, and confirm the actual website displays the correct image again.

Complete the private S3 connection lab first. This fresh environment supplies a website already authorized to read three private covers and projects.json. You will enable versioning and create the new versions yourself; no earlier resources or credentials are needed.

Certification Relevance

Certification Exam task Practice
AWS Certified Cloud Practitioner (CLF-C02) Task 3.6 Use S3 Versioning to preserve and recover stored application content.

Lab Overview

Recover an overwritten portfolio cover with S3 versions, and confirm the actual website displays the correct image again.

Preserve an Image Version

In this step, you will enable versioning and save the correct AURA cover’s version ID for recovery.

Open the portfolio from AWS View. AURA should show skincare packaging. Load this lab’s identifiers and confirm its bucket name:

cd /home/labex/project
source website.env
echo "$PORTFOLIO_BUCKET"

S3 Versioning keeps multiple versions under one object key. Normal reads return the current version; a VersionId selects a specific saved version. Enable versioning for this bucket:

aws s3api put-bucket-versioning \
  --bucket "$PORTFOLIO_BUCKET" \
  --versioning-configuration Status=Enabled

The successful update has no output. Read the setting back and confirm Status is Enabled:

aws s3api get-bucket-versioning --bucket "$PORTFOLIO_BUCKET"

Existing objects retain their null version: enabling versioning does not assign new IDs to earlier uploads. Re-upload the correct AURA file to create a named version. put-object uploads the --body file. $(...) saves the VersionId selected by --query and --output text:

--content-type image/webp identifies the uploaded bytes as a WebP image. Copy the complete command: each ending backslash continues onto the next line.

ORIGINAL_VERSION=$(aws s3api put-object \
  --bucket "$PORTFOLIO_BUCKET" --key images/aura-brand.webp \
  --body portfolio-assets/images/aura-brand.webp --content-type image/webp \
  --query VersionId --output text)
echo "$ORIGINAL_VERSION"

The ID identifies a version, not the bucket or key. Keep this Terminal session open: ORIGINAL_VERSION is needed in step 3. Refresh the site; its AURA cover is still correct because you uploaded the same image.

This fresh lab supplies its own website and four private portfolio objects; identifiers vary.

Observe an Incorrect Update

In this step, you will upload a deliberately incorrect cover and see the result visitors receive.

The supplied aura-draft.webp contains ECHO’s record image, representing a wrong file selected for AURA. Uploading it to AURA’s same key creates a new current version while preserving the earlier correct one:

aws s3api put-object \
  --bucket "$PORTFOLIO_BUCKET" --key images/aura-brand.webp \
  --body aura-draft.webp --content-type image/webp \
  --query VersionId --output text

The command displays the draft’s new VersionId. Refresh the portfolio: AURA now shows a record instead of skincare packaging. Its AURA label remains, while FORMA and ECHO keep their original images.

Real checkpoint: publishing the wrong current version changes the website image.

Inspect only AURA’s version history. --query filters the response to that key and selects VersionId and IsLatest; --output table makes the result easier to compare:

aws s3api list-object-versions \
  --bucket "$PORTFOLIO_BUCKET" \
  --query 'Versions[?Key==`"images/aura-brand.webp"`].{VersionId:VersionId,IsLatest:IsLatest}' \
  --output table

Expect three rows: the initial null version and two named versions. IsLatest=True marks the incorrect draft now served by the website; the saved ORIGINAL_VERSION remains available. Order and IDs may differ. The recovery data is in S3, beyond merely having a local original.

Recover the Earlier Image

In this step, you will retrieve the saved correct version and upload its bytes as the new current cover.

get-object downloads an object. --version-id selects ORIGINAL_VERSION rather than the bad current version; recovered-aura.webp is the local destination:

aws s3api get-object \
  --bucket "$PORTFOLIO_BUCKET" --key images/aura-brand.webp \
  --version-id "$ORIGINAL_VERSION" recovered-aura.webp

After the download, the CLI displays object metadata. Check that VersionId matches the saved ID; you do not need to interpret each checksum field yet. Next, check the file’s actual content.

Compare the recovered file with the supplied correct image. No output and a returned prompt from cmp mean the bytes match:

cmp portfolio-assets/images/aura-brand.webp recovered-aura.webp

Downloading alone does not change what the website reads. Upload the recovered file to the same key to create a new current version:

aws s3api put-object \
  --bucket "$PORTFOLIO_BUCKET" --key images/aura-brand.webp \
  --body recovered-aura.webp --content-type image/webp \
  --query VersionId --output text

Refresh the site: AURA should again show skincare packaging. FORMA, ECHO and projects.json remain unchanged. Read the history once more:

Real checkpoint: the recovered earlier bytes are served as the current website image.

aws s3api list-object-versions \
  --bucket "$PORTFOLIO_BUCKET" \
  --query 'Versions[?Key==`"images/aura-brand.webp"`].{VersionId:VersionId,IsLatest:IsLatest}' \
  --output table

Four AURA versions now remain. The restored version has IsLatest=True; the bad draft is retained in history but is no longer current. You have recovered the live result while preserving what happened.

Summary

You enabled S3 versioning, saved a correct version, observed a wrong upload and restored the earlier bytes as a new current version. The actual website and version history confirmed recovery, while other portfolio materials stayed unchanged.

Official references: S3 Versioning and retrieving object versions.