3 ms·
Try to understand this monster, taken from: https://s3.amazonaws.com/cloudformation-templates/CloudFormationSample_WordPress.template https://s3.amazonaws.com/
by nivertech 16y ago
Try to understand this monster, taken from:
https://s3.amazonaws.com/cloudformation-templates/CloudFormationSample_WordPress.template https://s3.amazonaws.com/cloudformation-templates/CloudForma...
Amazon guys trying to reinvent JS in JSON:
"WordPressLaunchConfig" : {
"Type" : "AWS::AutoScaling::LaunchConfiguration",
"Properties" : {
"ImageId" : "ami-16668c7f",
"SecurityGroups" : [ { "Ref" : "WordPressEC2Security" } ],
"UserData" : { "Fn::Base64" : { "Fn::Join" : [ "\n", [ { "Fn::Join" : [ "=", [ "dbName", { "Ref" : "WordPressDBName" } ] ] }, { "Fn::Join" : [ "=", [ "dbUser", { "Ref" : "WordPressUser" } ] ] }, { "Fn::Join" : [ "=", [ "dbPassword", { "Ref" : "WordPressPwd" } ] ] }, { "Fn::Join" : [ "=", [ "dbHost", { "Fn::GetAtt" : [ "WordPressDB" , "Endpoint.Address" ] } ] ] }, { "Fn::Join" : [ "=", [ "dnsName", { "Fn::GetAtt" : [ "WordPressELB" , "DNSName" ] } ] ] } ] ] } },
"InstanceType" : { "Ref" : "InstanceType" }
}
},
After some identation cleanup:
{ "Fn::Base64" :
{ "Fn::Join" :
[ "\n", [
{ "Fn::Join" : [ "=", [ "dbName", { "Ref" : "WordPressDBName" } ] ] },
{ "Fn::Join" : [ "=", [ "dbUser", { "Ref" : "WordPressUser" } ] ] },
{ "Fn::Join" : [ "=", [ "dbPassword", { "Ref" : "WordPressPwd" } ] ] },
{ "Fn::Join" : [ "=", [ "dbHost", { "Fn::GetAtt" : [ "WordPressDB" , "Endpoint.Address" ] } ] ] },
{ "Fn::Join" : [ "=", [ "dnsName", { "Fn::GetAtt" : [ "WordPressELB" , "DNSName" ] } ] ] }
] ]
}
}
DSL like this would be much more readable and maintainable:
base64(<<<USERDATA
dbName=$WordPressDBName
dbUser=$WordPressUser
dbPassword=$WordPressPwd
dbHost=${GetAtt("WordPressDB","Endpoint.Address")}
dnsName=${GetAtt("WordPressELB","DNSName")}
USERDATA)
And this just a small example, I wander how complex this JSON will be for real-life cases.
Instead of reinventing Javascrict in JSON, they should have added some simple shell-like parameter substitution DSL (simple sigils) or allow some sand-boxed sanitized Javascript.
Now I understand why tools like Chef/OpsCode using Ruby for this.