Powershell Variables - Issue replacing parameter value when using AWS CLI for Cloudformation

101 Views Asked by At

I am currently trying to set up CloudFormation to use AWS Config and set up the AWS default rule for Public RDS checking.

I am trying to deploy this using powershell with variables, code below.

# Variables
$default_region = 'eu-west-1'
$aws_profile = Read-Host -Prompt 'Input AWS CLI profile name'

if (!($aws_region = Read-Host "Enter Region [$default_region]")) { $aws_region = $default_region }
if (!($environment = Read-Host "Enter Environment Name [$aws_profile]")) { $environment = $aws_profile }
$topicname = "rds_instance_public_access_check_$($aws_region)"

$sns_message = "Public RDS Detected in $($environment) - $($aws_region)"

# Create the RDS Public Instance stack
aws cloudformation create-stack --stack-name rds-instance-public-access-check-rules --template-body file://config_public_rds.yml --parameters ParameterKey=ViolationMessage,ParameterValue=$sns_message ParameterKey=TopicName,ParameterValue=$topicname --profile $aws_profile --region $aws_region

The CloudFormation template works as expected, if i hardcode the $topicName and $sns_message variable it creates the stack as expected.

The parameters being passed for creation are the $ variable values when checking the console.

If i Write out the parameters outside of the CLI they also work, only when using it like the above does it seem to ignore the parameter set.

The values being passed are also not the issue as I have tested this with simple string values and that also fails.

Tried to run the above code, expecting a CloudFormation stack to be created on the AWS profile passed in.

Permissions are tested and working. CloudFormation template replaced with hard values tested and working. Powershell replaced with hardcoded values tested and working. Variables changed to simple strings, not working.

Thank you in advance.

Gavin

0

There are 0 best solutions below