简体   繁体   English

如何在 Cloud Formation 模板中运行 SQL 查询以在 AWS RDS 中启用 Delayed_Durability

[英]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.

相关问题 在 AWS Cloud Formation 模板中创建嵌套 If else - Create Nested If else in AWS Cloud Formation Template 如何在 AWS Lambda 触发器云形成模板中提供多个 SQS 队列名称 - how to provide multiple SQS queue name in AWS Lambda trigger cloud formation template 如何在 AWS-CDK 应用程序中形成没有 cdk synt 和 cdk deploy 的云形成模板? - How to form cloud formation template without cdk synt and cdk deploy in AWS-CDK app? 在 AWS 云形成中扮演的角色 - Assumable role in an AWS cloud formation 如何自动获取DNS ELB ELB AWS Cloud formation - how to get DNS ELB automatically ELB AWS Cloud formation 将现有 AWS 机密引入 Cloud Formation 堆栈 - Bring existing AWS secrets into Cloud Formation stack 如何在谷歌云 sql 服务器中启用 CDC 以进行 AWS DMS 复制? - how to enable CDC in google cloud sql server for AWS DMS replication? 如何运行 SQL 命令在 AWS RDS 上自动创建或更新数据库 - How to run SQL commands to create or update a database in an automated manner on the AWS RDS 删除 AWS 云形成堆栈及其创建的资源 - Delete AWS Cloud formation stack with resources created by it 使用 aws sdk 命令行在自动缩放中形成云 - Cloud Formation in auto scaling using aws sdk command line
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM