Skip to content

Instantly share code, notes, and snippets.

@julienperon
julienperon / tag.sh
Created May 7, 2021 07:38
This shell tags all resources in a bucket. This is meant to be used at deploy time with cdk in conjunction with a life cycle policy to avoid keeping useless files.
#!/usr/bin/env bash
# This script manages a simple tagging lifecycle: current -> previous -> outdated.
# It is meant to be used with a bucket lifecycle policy, in order to delete all outdated tags.
# Why ?
# The deployment bucket has to be cleaned regularly, otherwise it will become a mess.
# However, having a simple lifecycle policy based on time is dangerous
# Deleting old objects without a recent deployment can lead to deletion of currently used assets.
# In case of error in the next deployment, the stack will try to rollback and will not find assets