Recently, I wanted to delete some of my configuration groups from the AWS Parameter Store. I use the hierarchical concept of the Parameter Store and thus wanted to recursively delete all options under a specific prefix.
It seems neither the AWS command line interface nor the AWS web console have this capability at the moment. But with a bit of shell scripting it is quite simple, so here’s again a little AWS shell helper. The tricky part is that the Parameter Store API only allows you to specify a maximum of 10 items to delete per call.
Use at your own caution. I’m not responsible if your Parameter Store is empty after executing this script.
#!/usr/bin/env bash region=$1 path=$2 if [[ -z "$region" ]]; then echo "Please specify a region." exit 1 fi if [[ -z "$path" ]]; then echo "Please specify a non empty path." exit 1 fi while true; do parameters_to_delete=$(aws --region $region ssm get-parameters-by-path --recursive --path $path --query Parameters.Name | jq -r '.[0:10]|join(" ")') if [[ -z "$parameters_to_delete" ]]; then break fi echo "Deleting the following parameters: $parameters_to_delete" aws --region $region ssm delete-parameters --names $parameters_to_delete done
Instead of subslicing with
jq it would also have been possible to just
iterate all parameters and delete one-by-one, but this way I learnt something
It’s also interesting that the deletion in Parameter Store seems to be only eventually consistent, as my script tries to delete the same parameters a few times (i.e. even though I already deleted them, they are still returned on a query).I do not maintain a comments section. If you have any questions or comments regarding my posts, please do not hesitate to send me an e-mail to email@example.com.