DEV Community

Cover image for Avoiding phantom content on your S3 static site
Adam Davis
Adam Davis

Posted on • Originally published at brewinstallbuzzwords.com

Avoiding phantom content on your S3 static site

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>
Enter fullscreen mode Exit fullscreen mode

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.

Diagram of deleted content no longer being linked to, but continuing to exist

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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

More Content

If you liked this, you might also like some of my other posts. If you want to be notified of my new posts, follow me on Dev or subscribe to my brief monthly newsletter.

Oldest comments (0)