Created
June 21, 2022 03:21
-
-
Save pwmcintyre/6040cb63066cf1b9a8c44badb5594fa6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Deletes all SSM Parameters with the given prefix. | |
Example usage: | |
$ npm i @aws-sdk/client-ssm | |
$ AWS_PROFILE=nbos-ris-np-admin AWS_REGION=us-west-2 SSM_PATH_PREFIX=/ris/dev/1/wombatch/ npx ts-node . | |
*/ | |
import { SSMClient, DeleteParametersCommand, GetParametersByPathCommand } from "@aws-sdk/client-ssm" | |
const Path = process.env["SSM_PATH_PREFIX"] | |
;(async () => { | |
const client = new SSMClient({}) | |
let NextToken: string | undefined | |
while (true) { | |
// list page | |
const data = await client.send(new GetParametersByPathCommand({ | |
Path, | |
Recursive: true, | |
NextToken, | |
})) | |
// no results | |
if ( !( data.Parameters?.length ) ) return | |
// process | |
const Names = data.Parameters.map(({ Name }) => Name!) | |
await client.send( new DeleteParametersCommand({ | |
Names, | |
})) | |
console.log( "deleted", Names ) | |
// paginate | |
if ( !data.NextToken ) return | |
NextToken = data.NextToken | |
} | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment