简体   繁体   English

如何在启动数据库时从 cloudformation 模板为 RDS 创建模式?

[英]How to create schema for RDS from cloudformation template while launching the database?

I'm trying to install MYSQL (RDS) from cloud formation template.我正在尝试从云形成模板安装 MYSQL (RDS)。 Is there a way to run SQL DDL script so we can create a schema at the time of database setup有没有办法运行 SQL DDL 脚本,这样我们就可以在数据库设置时创建一个模式

Your infrastructure code(no matter it is CloudFormation or CDK, etc) should only care about provision the resources in the cloud, and nothing else.您的基础设施代码(无论是 CloudFormation 还是 CDK 等)应该只关心在云中提供资源,而不关心其他。

The schema creation can be done after the database is launched, through AWS CodeBuild(I use flyway to do that https://flywaydb.org/ ).模式创建可以在数据库启动后通过 AWS CodeBuild 完成(我使用 flyway 来做到这一点https://flywaydb.org/ )。

What I did is:我所做的是:

  1. I have a CDK package to create the infrastructure, where my RDS is provisioned.我有一个 CDK package 来创建我的 RDS 已配置的基础设施。 This package only cares about infrastructure, and nothing else.这个 package 只关心基础设施,没有别的。

  2. I have a separate CDK package, which aims to perform schema migration only.我有一个单独的 CDK package,旨在仅执行模式迁移。 This pipeline track my schema repository, and consists of CodeBuild where flyway can run to migrate schema(including schema initialization).该管道跟踪我的模式存储库,并由 CodeBuild 组成,flyway 可以在其中运行以迁移模式(包括模式初始化)。 The first time the CodeBuild run will initialize the database with the defined schema, once a new schema change is made and code submitted to the repository, the pipeline will get triggered, and build a new docker image with the new schema, and run the new docker image against the database to update schema. CodeBuild 第一次运行将使用定义的模式初始化数据库,一旦进行新模式更改并将代码提交到存储库,管道将被触发,并使用新模式构建新的 docker 图像,并运行新的docker 图像针对数据库更新模式。 The database credential can be fetched from secret-manager as environment variables in CodeBuild.数据库凭证可以作为 CodeBuild 中的环境变量从 secret-manager 中获取。

The pipeline looks like this:管道看起来像这样:

SourceStage => Docker Build Stage(using CodeBuild to build a docker image with the new schema) => Flyway Stage(using CodeBuild to run the docker image)

Of course, you can merge above two packages into one package, as long as you separate code well to know that one part is for infrastructure only, and one is for database schema migration pipeline.当然,你也可以把上面两个包合并成一个package,只要你把代码分离好就知道一部分只做基础设施,一部分做数据库schema迁移管道。

There is not a way to do this natively in CloudFormation. 在CloudFormation中没有办法本地执行此操作。 You'll have to have a script run after the template has been deployed that will run the DDL 在部署了将运行DDL的模板之后,您必须运行脚本

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何处理无法从 AWS 上的 CloudFormation 模板创建错误? - How to handle failed to create erros from CloudFormation template on AWS? 如何使用 AWS CloudFormation 连接到现有 RDS 数据库? - How can I connect to an existing RDS database using AWS CloudFormation? 如何在现有 su.net 或我创建的 su.net 模板中指定 su.netID? - How do I specify subnetID in cloudformation template, either from existing subnet or one that I create? AWS::RDS::DBInstance 不是从 cloudformation 创建的 - AWS::RDS::DBInstance is not being created from cloudformation AWS CloudFormation:无法创建 RDS 数据库,因为数据库安全组无法引用 web 服务器的安全组 - AWS CloudFormation: unable to create RDS database because database security group cannot reference the web server's security group 用于创建多个 SQS 的 Cloudformation 模板 - Cloudformation template to create multiple SQS Cloudformation / ECS - 如何直接从模板中检索任务定义 IP? - Cloudformation / ECS - How to retrieve taskdefinition IP directly from the template? 如何从 CloudFormation 模板启用/禁用 Cloudfront 日志记录? - How to enable/disable Cloudfront logging from CloudFormation template? 使用一个 cloudFormation 模板从 zip 文件和 S3 存储桶创建一个 lambda - Create a lambda from zip file and and an S3 bucket using one cloudFormation Template 将 csv 文件从 s3 导入 rds PostgreSQL 数据库 > 错误:模式“aws_commons 不存在 - Importing a csv file from s3 into rds PostgreSQL Database > Error: schema "aws_commons does not exist
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM