Skip to content

Instantly share code, notes, and snippets.

@jcefoli

jcefoli/aws-ssm-param.ps1

Last active Mar 9, 2021
Embed
What would you like to do?
Powershell AWS CLI SSM Parameter Store Helper
<#
.SYNOPSIS
Helper script to manage SSM parameters
.PARAMETER name
SSM key name to set
.PARAMETER value
SSM key value to set
.PARAMETER profileName
aws profile name
.PARAMETER plainText
Can be omitted. Defaults to false, which means by default, we store everything as a SecureString. Set this to store value as plain text String
.EXAMPLE
./aws-ssm-param.ps1 -name "Key" -value "value" -profile "joelab"
./aws-ssm-param.ps1 -name "Key" -value "value" -profile "joelab" -plainText
./aws-ssm-param.ps1 -name "Key" -profile "joelab" -delete
#>
[CmdletBinding(DefaultParameterSetName="defaultSet")]
Param(
[Parameter(ParameterSetName="defaultSet",Mandatory = $True)]
[Parameter(ParameterSetName="deleteSet",Mandatory = $True)]
[string]$name,
[Parameter(ParameterSetName="defaultSet",Mandatory = $True)]
[string]$value,
[Parameter(ParameterSetName="defaultSet",Mandatory = $True)]
[Parameter(ParameterSetName="deleteSet",Mandatory = $True)]
[string]$profile,
[Parameter(ParameterSetName="defaultSet")]
[switch]$plainText = $false,
[Parameter(ParameterSetName="deleteSet")]
[switch]$delete = $false
)
switch ($delete)
{
$true {
aws ssm delete-parameter --name "$name" --region "us-east-2" --profile "$profile"
Write-Output "Deleted `"$name`""
exit
break
}
default { break }
}
switch ($plainText)
{
$true { $type = "String"; break }
default { $type = "SecureString"; break }
}
# Set Parameter
. aws ssm put-parameter --name "$name" --value "$value" --type "$type" --overwrite --region "us-east-2" --profile "$profile"
. aws ssm get-parameter --name "$name" --with-decryption --region "us-east-2" --profile "$profile" --no-cli-pager
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment