I’m trying to fetch a parameter value from the AWS Systems Manager Parameter Store using PowerShell. Using the ‘aws ssm get-parameters’. But I’m encountering issues.
Here’s the code snippet I’m using:
function get_param_value($parameter){
aws ssm get-parameters --name $parameter --with-decryption | ConvertFrom-Json | ForEach-Object { $_.Parameters[0].Value }
}
$server = get_param_value("/webhost/db/host")
Write-Output "server: $server"
Error:
+ aws ssm get-parameters --name "$parameter" --with-decryption | Co ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
Can someone help me identify what might be wrong with this code or suggest a better approach to retrieve the parameter value using PowerShell’s AWS CLI? Any insights or alternative methods would be greatly appreciated. Thanks in advance!