//Stack还支持用户钩子脚本执行配置EC2的操作
“UserData” : { “Fn::Base64” : { “Fn::Join” : [“”,[
“#!/bin/bash\n”,
“yum update -y aws-cfn-bootstrap\n”,
“/opt/aws/bin/cfn-init -s “,{ “Ref” : “AWS::StackId” },” -r WebServer “,
” –region “,“\n”,
“/opt/aws/bin/cfn-signal -e $? ‘”,{ “Ref” : “WaitHandle” },“‘\n”,
“# Setup correct file ownership\n”,
“chown -R apache:apache /var/www/html/wordpress\n”,
“# Add keys and salts to the config file\n”,
“wp_config=/var/www/html/wordpress/wp-config.php\n”,
“GET https://api.wordpress.org/secret-key/1.1/salt/ >> $wp_config\n”,
“echo \&;define(‘WPLANG’,”);\&; >> $wp_config\n”,
“echo \&;define(‘WP_DEBUG’,false);\&; >> $wp_config\n”,
“echo \&;\\$table_prefix = ‘wp_’;\&; >> $wp_config\n”,
“echo \&;if ( !defined(‘ABSPATH’) )\&; >> $wp_config\n”,
“echo \&; define(‘ABSPATH’,dirname(__FILE__) . ‘/’);\&; >> $wp_config\n”,
“echo \&;require_once(ABSPATH . ‘wp-settings.php’);\&; >> $wp_config\n”
]]}}
}
},
“WaitHandle” : {
“Type” : “AWS::CloudFormation::WaitConditionHandle”
},
“WaitCondition” : {
“Type” : “AWS::CloudFormation::WaitCondition”,
“DependsOn” : “WebServer”,
“Properties” : {
“Handle” : {“Ref” : “WaitHandle”},
“Timeout” : “600”
}
},
//数据库实例.AWS提供给用户的是数据库实例,而不是某个数据库.用户得到数据库实例的信息之后,可以自行创建数据库.
//AWS还支持创建实例的时候创建数据库,这种场景通常是一个实例一个数据库.下面的DBName参数是可选的.
“DBInstance” : {
“Type”: “AWS::RDS::DBInstance”,
“Properties”: {
“DBName” : { “Ref” : “DBName” },
“Engine” : “MySQL”,
“MasterUsername” : { “Ref” : “DBUsername” },
“DBInstanceClass” : { “Ref” : “DBClass” },
“DBSecurityGroups” : [{ “Ref” : “DBSecurityGroup” }],
“AllocatedStorage” : { “Ref” : “DBAllocatedStorage” },
“MasterUserPassword”: { “Ref” : “DBPassword” }
}
},
“DBSecurityGroup”: {
“Type”: “AWS::RDS::DBSecurityGroup”,
“Properties”: {
“DBSecurityGroupIngress”: { “EC2SecurityGroupName”: { “Ref”: “WebServerSecurityGroup”} },
“GroupDescription” : “Frontend Access”
}
},
(编辑:ASP站长网)
|