Odin, or Wōtan, is a Norse god who directs the valkyries and is the guardian of Valhalla. Half of those who perish in combat are welcomed by him into his majestic halls where they prepare for the final battle against Fenrir during the events of Ragnarök.
This serverless application periodically checks the status of CloudFormation stacks in your AWS environment and sends the stale ones to Valhalla.
Odin currently determines that a stack is stale and should be removed when it doesn't fit any of the following three criteria:
- Tagging: If a stack is tagged with the stage 'Production' or 'Automation' (or either's derivatives, like 'Prod' or 'Auto') then it is ineligible for deletion
- Status: If a stack's status is in a failure or in-progress state then it is ineligible for deletion
- Age: If a stack has been updated recently then it is ineligible for deletion
If a stack doesn't match one of the above criteria then it is removed.
Odin is built with the Serverless Framework - see their documentation for more about the tool and how to use it.
To change the frequency with which Odin runs and the settings used to determine whether a stack is eligible for deletion modify the values in odin.yml and redeploy the application.
Unlike his Norse namesake Odin is unable to practice magic and cannot remove stacks that aren't self-removing.
A common example of this situation is a stack which creates an S3 bucket that is later filled with files. If the stack doesn't contain the resources necessary to empty and then delete this bucket any stack delete commands (whether triggered by Odin, manually, or any other means) will end with the stack in an error state. Don't treat your stacks this way - let them enter Valhalla with honor!
For this specific scenario you can use a tool like the empty-s3-bucket
service found in Lambda Utilities in combination with a custom CloudFormation resource to empty buckets when a stack is deleted. See the infrastructure section of Santa Swap UI for a real-world example of how this can be achieved within a stack.
Another approach is to let Odin empty your S3 buckets for you prior to calling the delete stack command. This approach requires you to output the bucket name in your CloudFormation stack, and then add the output key name to odin.yml. By default Odin will empty the deployment buckets created by the Serverless Framework.
Murray, Alexander (1874). Manual of Mythology : Greek and Roman, Norse, and Old German, Hindoo and Egyptian Mythology. London, Asher and Co. This illustration is from plate XXXV. Digitized version of the book by the Internet Archive, https://archive.org/details/manualofmytholog00murruoft Published earlier in Reusch, Rudolf Friedrich. 1865. Die nordischen Göttersagen.