[英]How to run a SQL query in Cloud Formation template to enable Delayed_Durability in AWS RDS
I have a Cloud Formation template to create a SQL DB in the RDS and want to enable Delayed_Durability feature by default in it by running this query: ALTER DATABASE dbname SET DELAYED_DURABILITY = FORCED;
我有一个 Cloud Formation 模板,用于在 RDS 中创建一个 SQL 数据库,并希望通过运行以下查询在其中默认启用 Delayed_Durability 功能:
ALTER DATABASE dbname SET DELAYED_DURABILITY = FORCED;
Is there a way to run this query right after db instance is created through CF template?有没有办法在通过 CF 模板创建数据库实例后立即运行此查询? My CF template looks like this:
我的 CF 模板如下所示:
"Type":"AWS::RDS::DBInstance",
"Properties":{
"AllocatedStorage":"200",
"AutoMinorVersionUpgrade":"false",
"BackupRetentionPeriod":"1",
"DBInstanceClass":"db.m4.large",
"DBInstanceIdentifier":"mydb",
"DBParameterGroupName": {
"Ref": "MyDBParameterGroup"
},
"DBSubnetGroupName":{
"Ref":"dbSubnetGroup"
},
"Engine":"sqlserver-web",
"EngineVersion":"13.00.4422.0.v1",
"LicenseModel":"license-included",
"MasterUsername":"prod_user",
"MasterUserPassword":{ "Ref" : "dbpass" },
"MonitoringInterval":"60",
"MonitoringRoleArn": {
"Fn::GetAtt": [
"RdsMontioringRole",
"Arn"
]
},
"PreferredBackupWindow":"09:39-10:09",
"PreferredMaintenanceWindow":"Sun:08:58-Sun:09:28",
"PubliclyAccessible": false,
"StorageType":"gp2",
"StorageEncrypted": true,
"VPCSecurityGroups":[
{
"Fn::ImportValue":{
"Fn::Sub":"${NetworkStackName}-RDSSecGrp"
}
}
],
"Tags":[
{
"Key":"Name",
"Value":"my-db"
}
]
}
}
Is there a way to run this query right after db instance is created through CF template?
有没有办法在通过 CF 模板创建数据库实例后立即运行此查询?
Depends.要看。 If you want to do it from within CloudFormation (CFN) then sadly, you can't do this using plain CFN.
如果您想从 CloudFormation (CFN) 中执行此操作,那么遗憾的是,您无法使用普通 CFN 执行此操作。 To do it from CFN, you would have to develop a custom resource .
要从 CFN 执行此操作,您必须开发自定义资源。 The resource would be in the form of lambda function .
资源将采用lambda function的形式。 You would pass the DB details to the function in your CFN, and it could run and execute your query.
您可以将数据库详细信息传递给 CFN 中的 function,它可以运行并执行您的查询。 It could also return any results you want to your CFN for further use.
它还可以将您想要的任何结果返回给您的 CFN 以供进一步使用。
In contrast, if you create your CFN stack using AWS CLI or SDK , then once create-stack
call is completed, you can run your query from bash or any programming language you use do deploy your stack.相反,如果您使用AWS CLI 或 SDK创建 CFN 堆栈,则
create-stack
调用完成后,您可以从 bash 或您使用的任何编程语言运行查询来部署您的堆栈。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.