使用CloudFormation创建RDS数据库实例时,是否可以运行初始SQL? [英] Is there a way to run initial SQL when creating an RDS database instance using CloudFormation?

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

问题描述

我正在使用CloudFormation通过以下方式创建RDS实例:

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"
                }
            }
        }

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

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?

推荐答案

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

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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆