Deleting versions from a Linode s3 bucket

So...this wasn't as straight forward as I thought...

Problem/story

Enabling versioning for s3 buckets is standard practice for terraform's s3 backend, which Linode supports...kind of... While yes technically Linode supports the versioning, it doesn't support deleting the versions from the web-ui... 🤦.

Alright, that's fine I've heard they have a CLI...surely they'll support deleting it from there, right?

Ok...ok...just one more package and...

GAHHH...this was very frustrating... (source)

Solution

I use pipx for all my binaries I install, so that's what I'll use for installing python pip package, if you only want to use pip it's pretty much the exact same (just pip install boto instead of pipx inject linode-cli boto.

pipx install linode-cli
# authenticate with PAT (personal access token)
linode-cli configure --token
pipx inject linode-cli boto
# validate able to reach linode buckets
linode-cli obj ls


pipx install awscli
# used for aws auth
cat ~/.config/linode-cli
aws configure

# https://towardsthecloud.com/aws-cli-empty-s3-bucket
aws s3api delete-objects --endpoint=https://us-east-1.linodeobjects.com --bucket=<bucket_name> --delete "$(aws s3api list-object-versions --endpoint=https://us-east-1.linodeobjects.com --bucket "<bucket_name>" --output=json --query='{Objects: Versions[].{Key:Key,VersionId:VersionId}}')"
aws s3 rm --endpoint-url=https://us-east-1.linodeobjects.com  --recursive s3://<bucket_name>

Conclusion

alright, well this is now a guide for me when I need to delete versioned object out of Linode's s3 object storage... 🤦