简体   繁体   English

AWS SSM 参数存储

[英]AWS SSM Parameters Store

Is there anyway to just nuke / remove all items in AWS Parameters Store?无论如何,是否可以直接删除/删除 AWS 参数存储中的所有项目?

All the command line I found are to remove it either one by one or remove it given a list of names.我找到的所有命令行都是将它一个一个地删除,或者在给出一个名称列表的情况下将其删除。

I also tried using我也尝试使用

aws ssm delete-parameters --cli-input-json test.json

with test.json file looks like this与 test.json 文件看起来像这样

{
    "Names": [
        "test1",
        "test2"
    ]
}

still does not work..还是不行。。

Ideally if I can use --query and use it as is, that'd be great.理想情况下,如果我可以使用 --query 并按原样使用它,那就太好了。

I'm using --query like so我正在使用 --query 像这样

aws ssm get-parameters-by-path --path / --max-items 2 --query 'Parameters[*].[Name]'

When you need to delete all parameters by path in AWS Systems Manager Parameter Store and there are more than 10 parameters you have to deal with pagination.当您需要在 AWS Systems Manager Parameter Store 中按路径删除所有参数并且有 10 多个参数时,您必须处理分页。 Otherwise, an the command will fail with the error:否则,命令将失败并显示错误:

An error occurred (ValidationException) when calling the DeleteParameters operation: 1 validation error detected: Value '[/config/application/prop1, ...]' at 'names' failed to satisfy constraint: Member must have length less than or equal to 10

The following Bash script using AWS CLI pagination options deletes any number of parameters from AWS SSM Parameter Store by path:以下使用AWS CLI 分页选项的Bash 脚本按路径从 AWS SSM Parameter Store 中删除任意数量的参数:

#!/bin/bash

path=/config/application_dev/

while : ; do
  aws ssm delete-parameters --names $(aws ssm get-parameters-by-path --path "$path" --query "Parameters[*].Name" --output text --max-items 10 $starting_token | grep -v None)
  next_token=$(aws ssm get-parameters-by-path --path "$path" --query NextToken --output text --max-items 10 | grep -v None)
  if [ -z "$next_token" ]; then
    starting_token=""
    break
  else
    starting_token="--starting-token $next_token"
  fi
done

You can combine get-parameters-by-path with delete-parameters :您可以将get-parameters-by-pathdelete-parameters

aws ssm delete-parameters --names `aws ssm get-parameters-by-path --path / --query Parameters[].Name --output text`

I tested it by creating two parameters, then running the above command.我通过创建两个参数来测试它,然后运行上面的命令。 It successfully deleted by parameters.通过参数成功删除。

This is my one line solution for this:这是我的单行解决方案:

$ for key in $(aws ssm get-parameters-by-path --path "/" --recursive | jq -r '.Parameters[] | .Name' | tr '\r\n' ' '); do aws ssm delete-parameter --name ${key}; done

NOTE: Be careful if you copy & paste this as it will remove everything under "/"注意:复制粘贴时要小心,因为它会删除“/”下的所有内容

试试这个并执行多次

aws ssm delete-parameters --names `aws ssm get-parameters-by-path --path / --recursive --query Parameters[].Name --output text --max-items 9`

Adding to the above.补充以上。 I had to delete around 400 params from the parameter store.我不得不从参数存储中删除大约 400 个参数。 Ran the below in command line and it did it!在命令行中运行以下命令,它做到了! (Change 45 in for loop to whatever number you like); (将 for 循环中的 45 更改为您喜欢的任何数字);

for ((n=0;n<**45**;n++)); do
    aws ssm delete-parameters --names `aws ssm get-parameters-by-path --path / --recursive --query Parameters[].Name --output text --max-items 9`
done

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM