- Newest
- Most votes
- Most comments
Hello,
You can use CloudFormation custom resource to initialize rds in cloudformation, this repository is an example that may help you:
Steps to Execute SQL Queries After RDS Creation with CloudFormation
Create the RDS Instance using CloudFormation:
In your CloudFormation template, define the RDS instance and other necessary resources like security groups, subnets, etc.
Create a Lambda Function:
This Lambda function will execute the SQL queries on the RDS instance after it is created. The function can be triggered either by a CloudWatch Event when the RDS instance is ready or by AWS Systems Manager after CloudFormation completes.
Create an SSM Document:
Store your SQL statements or stored procedures in an SSM Document. This allows you to pass the SQL commands securely and execute them via Lambda.
Add a CloudWatch Event Rule or SSM Automation:
Set up a CloudWatch Event Rule that triggers the Lambda function after the RDS instance is created and becomes available. Alternatively, you can use an SSM Automation document to trigger the Lambda function after the CloudFormation stack is complete.
IAM Roles and Permissions:
Ensure that the Lambda function has the necessary IAM permissions to execute queries on the RDS instance and to access the RDS instance credentials stored in AWS Secrets Manager (if applicable).
Example CloudFormation Template Snippet
Here’s a basic example to illustrate how you might set this up in CloudFormation:
Resources:
MyDBInstance:
Relevant content
- asked 2 years ago
- asked a year ago
- AWS OFFICIALUpdated 8 months ago
- AWS OFFICIALUpdated 6 months ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 4 days ago