Skip to content

Instantly share code, notes, and snippets.

@bboure
Last active October 30, 2024 16:51
Show Gist options
  • Save bboure/10a084ca30d442eae8ea6b622171681e to your computer and use it in GitHub Desktop.
Save bboure/10a084ca30d442eae8ea6b622171681e to your computer and use it in GitHub Desktop.
Delete SSM parameters by path prefix
aws ssm get-parameters-by-path --path '/path/to/prams' --recursive \
| jq .Parameters[].Name \
| xargs -L1 -I'{}' aws ssm delete-parameter --name {}
@avivka
Copy link

avivka commented May 11, 2022

aws ssm get-parameters-by-path --path '/path/to/prams' --recursive \ | jq '.Parameters[].Name' \ | xargs -L1 -I'{}' aws ssm delete-parameter --name {}
(with '' on the jq command) worked for me

@egarbi
Copy link

egarbi commented Dec 11, 2023

This doesn't require jq to be installed, also adding -t helps to see what are you actually deleting

aws ssm get-parameters-by-path --path '/path/to/prams' --recursive --query 'Parameters[].Name' \
xargs -t -L1 -I'{}' aws ssm delete-parameter --name {}

Tip

Better to use a role or user with restricted by-path permissions to avoid removing undesired keys

@barsulka
Copy link

aws ssm get-parameters-by-path --path '/path/to/prams' --recursive --query 'Parameters[].Name' --output text | tr '\t' '\n' | xargs -t -I'{}' aws ssm delete-parameter --name {}

@mrtaxi
Copy link

mrtaxi commented Oct 30, 2024

#!/bin/bash
AWS_REGION=""
PATH=""
PARAMETERS_FOR_REMOVE=$(aws ssm get-parameters-by-path --region $AWS_REGION --path "$PATH" --recursive --output text --query "Parameters[].Name")
echo $PARAMETERS_FOR_REMOVE
for PARAMETER in ${PARAMETERS_FOR_REMOVE[
]}; do
echo $PARAMETER
echo $PARAMETER >> $PATH.txt
aws ssm delete-parameter --region $AWS_REGION --name $PARAMETER
done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment