Avoiding phantom content on your S3 static site

by Adam Davis

Table of contents:

It’s spooky season! So in this post, we’re going to explore how to avoid being haunted by content you thought you deleted — but actually didn’t.

Using the CLI

If you’re hosting a static website using AWS S3, one of the easiest ways to update your site is with the sync CLI command:

aws s3 sync <LocalPath> <S3Uri>

Whether you’re running the command manually or as part of a CI/CD pipeline, it’s important to note that, by default, it will only add content.

This means that even if you intended to remove a page from your site and removed all links to it, the page could still be accessed by navigating to it directly.

Use the delete flag

In order to delete non-existing content using this command, you’ll have to use the --delete flag.

aws s3 sync <LocalPath> <S3Uri> --delete

Just be careful to only use the --delete flag when you actually want to delete content that isn’t present in the source directory.

Taking precautions

In general, it’s a good idea to run S3 CLI commands with the --dryrun flag to show what actions would be performed without actually performing them.

aws s3 sync <LocalPath> <S3Uri> --delete --dryrun

To read more about this command and other available options, see the documentation.

Adam Davis

Share this post: