Create an S3 website redirect object
📑 On this page
Part 59 of AWS from Zero. This lesson keeps the scope to one S3 behavior you can verify from the terminal.
What we are learning
WebsiteRedirectLocation is object metadata interpreted by the S3 website endpoint.
Before you run it
aws sts get-caller-identity
REGION="ap-south-1"
BUCKET="replace-with-your-private-demo-bucket"Use a private general purpose bucket that you own. Replace every placeholder before running a write or delete command.
The command
aws s3api put-object \
--bucket "$BUCKET" \
--key old-page \
--website-redirect-location "/new-page.html"A successful configuration command may return no output. Treat inspection as a separate required step.
Inspect the result
aws s3api head-object \
--bucket "$BUCKET" \
--key old-page \
--query "{Size:ContentLength,Redirect:WebsiteRedirectLocation}"Read the returned fields rather than assuming the write succeeded exactly as intended.
One tiny variation
aws s3api put-object \
--bucket "$BUCKET" \
--key docs \
--website-redirect-location "https://docs.example.com/"The redirect location can be a relative path or an absolute URL.
Common mistake
Normal S3 API GetObject calls do not follow website redirect behavior. Test through the bucket website endpoint.
Cleanup
aws s3 rm "s3://$BUCKET/old-page"
aws s3 rm "s3://$BUCKET/docs"Remove both redirect objects.
Next, we will learn Remove S3 static website configuration.