Reputation: 2859
Solution: Don't use yml.
I'm trying to pass parameters that hold the db name and the db password along with my aws cloudformation stack-create
command. I get back an error that doesn't make a whole lot of sense.
Value of property MasterUsername must be of type String
Now, one thing to know is that I have console access so I can literally see the password and username come back in the console as what was set. They both look like strings to me.
YAML Version
I'm defining the stack in a template like this:
Parameters:
DBUser:
Description: db user
Type: String
MinLength: '4'
MaxLength: '16'
AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
ConstraintDescription: some description
DBPass:
Description: db password
Type: String
MinLength: '8'
MaxLength: '36'
AllowedPattern: '[a-zA-Z0-9]*'
ConstraintDescription: must contain only alphanumeric characters
Resources:
AppNode:
(...)
DatabaseInstance:
Type: AWS::RDS::DBInstance
Properties:
DBName: app
DBInstanceClass: db.t2.micro
Engine: postgres
EngineVersion: 10
MasterUsername:
- !Ref DBUser
MasterUserPassword:
- !Ref DBPass
DatabaseSG:
Type: AWS::RDS::DBSecurityGroup
Properties:
GroupDescription: Security Group for RDS public access
DBSecurityGroupIngress:
- CIDRIP: 0.0.0.0/0
Inside of my .env
file I have this:
[
{
"ParameterKey": "DBUser",
"ParameterValue": "root"
},
{
"ParameterKey": "DBPass",
"ParameterValue": "mydbpassword"
}
]
I run this command:
aws cloudformation create-stack --stack-name app --template-body file://$PWD/stack.json --region us-west-2 --parameters file://$PWD/.env.json
for the file type.
So the first thing that comes to mind is that maybe it's getting those values as blank. That can't be the case though because if I don't pass a template or parameters at all it, throws a different error.
An error occurred (ValidationError) when calling the CreateStack operation: Parameters: [DBUser, DBPass] must have values
Did AWS redefine what a string is or what is going on here?
Upvotes: 1
Views: 6182
Reputation: 6804
MasterUsername must be of type String
Here you have a list (array), not string:
MasterUsername:
- !Ref DBUser
Use on the same line instead:
MasterUsername: !Ref DBUser
Upvotes: 0
Reputation: 13035
Sorry to say that external parameters are not supported via file for yaml files.
You can pass them in command line as a workaround.
Reference:
https://github.com/aws/aws-cli/issues/2275
There is still in work in progress.
Hope it helps.
EDIT1:
MasterUsername:
- ${DBUser}
MasterUserPassword:
- ${DBPass}
Looks like your YAML syntax is not correct.
Reference:
http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/quickref-general.html
Upvotes: 0
Reputation: 2863
Correct your template as below.
Resources:
AppNode:
(...)
DatabaseInstance:
Type: AWS::RDS::DBInstance
Properties:
DBName: app
DBInstanceClass: db.t2.micro
Engine: postgres
EngineVersion: 10
MasterUsername:
!Ref DBUser
MasterUserPassword:
!Ref DBPass
When you use - !Ref DBUser
, it signifies a LIST
in yaml, not String
.
MasterUserPassword
and MasterUserPassword
are both of type String
.
AWS supports both .yml
and .yaml
extensions. So there is no issue with you extensions.
Upvotes: 1