[英]Passing Parameter Files for CloudFormation Does Not Work with YML
Solution : Don't use yml.解决方案:不要使用 yml。
I'm trying to pass parameters that hold the db name and the db password along with my aws cloudformation stack-create
command.我正在尝试传递包含数据库名称和数据库密码的参数以及我的
aws cloudformation stack-create
命令。 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 YAML 版本
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:在我的
.env
文件中,我有这个:
[
{
"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? AWS 是否重新定义了字符串是什么或这里发生了什么?
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
.当您使用
- !Ref DBUser
,它表示 yaml 中的LIST
,而不是String
。 MasterUserPassword
and MasterUserPassword
are both of type String
. MasterUserPassword
和MasterUserPassword
都是String
类型。 AWS supports both .yml
and .yaml
extensions. AWS 支持
.yml
和.yaml
扩展。 So there is no issue with you extensions.所以你的扩展没有问题。
Sorry to say that external parameters are not supported via file for yaml files.很抱歉,yaml 文件不支持通过文件支持外部参数。
You can pass them in command line as a workaround.您可以在命令行中传递它们作为解决方法。
Reference:参考:
https://github.com/aws/aws-cli/issues/2275 https://github.com/aws/aws-cli/issues/2275
There is still in work in progress.工作仍在进行中。
Hope it helps.希望能帮助到你。
EDIT1:编辑1:
MasterUsername:
- ${DBUser}
MasterUserPassword:
- ${DBPass}
Looks like your YAML syntax is not correct.看起来您的 YAML 语法不正确。
Reference:参考:
http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/quickref-general.html http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/quickref-general.html
MasterUsername must be of type String
MasterUsername 必须是 String 类型
Here you have a list (array), not string:这里有一个列表(数组),而不是字符串:
MasterUsername:
- !Ref DBUser
Use on the same line instead:改为在同一行上使用:
MasterUsername: !Ref DBUser
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.