数据库实例时运行初始

数据库实例时运行初始

本文介绍了有没有办法在使用 CloudFormation 创建 RDS 数据库实例时运行初始 SQL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 CloudFormation 创建一个 RDS 实例:

资源": {我的数据库":{"类型": "AWS::RDS::DBInstance",特性": {"分配的存储": "5","DBInstanceClass": "db.m1.small","引擎": "MySQL","EngineVersion": "5.5","DBName": "mydb",主用户名":{"Ref": "DBUser"},主用户密码":{"Ref": "DBPassword"},数据库参数组名称":{"Ref": "myRDSParamGroup"}}}

一切正常.但是我需要在创建数据库时在数据库上运行初始 SQL,以设置我的应用程序架构.我目前的方法是让应用程序自行迁移,但我想在 CloudFormation 定义中进行.这可能吗?

解决方案

不,这不可能.但是,您可以让 EC2 实例连接到您的 RDS 实例来执行此操作.我可能会在 S3 中存储一个 .sql 文件,并在 EC2 实例上使用 cloud-init 脚本来下载文件并执行它.

I am creating an RDS instance using CloudFormation using this:

"Resources": {
        "myDB": {
            "Type": "AWS::RDS::DBInstance",
            "Properties": {
                "AllocatedStorage": "5",
                "DBInstanceClass": "db.m1.small",
                "Engine": "MySQL",
                "EngineVersion": "5.5",
                "DBName": "mydb",
                "MasterUsername": {
                    "Ref": "DBUser"
                },
                "MasterUserPassword": {
                    "Ref": "DBPassword"
                },
                "DBParameterGroupName": {
                    "Ref": "myRDSParamGroup"
                }
            }
        }

and it all works. But I need to run initial SQL on the DB when its created, to setup my apps schema. My current approach is to have the app self migrating, but I'd like to do it in the CloudFormation definition. Is this possible?

解决方案

No, it's not possible. However, you could have an EC2 instance connect to your RDS instance to do it. I'd probably store a .sql file in S3 and use a cloud-init script on the EC2 instance to download the file and execute it.

这篇关于有没有办法在使用 CloudFormation 创建 RDS 数据库实例时运行初始 SQL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 20:11