I want to create an AWS stack with the python aws-cdk library.
The requirements are as such: There must exist an aurora3 mysql database and it needs to have 2 tables (as a reduced example, lets say table1 needs to have 2 fields: id of integer type and name of string type, and table2 needs to have table1_id of integer which is a foreign key to table1, and a data field of string type
I have found some tutorials online on how to do this through the console, but I need to do it from within code, and not manually through the console, and the documentation seems lacking for this
The CDK code looks like this, call it from your app.py as you would normally
The CDK creates a trigger for a lambda the lambda updates the database using boto3. It is automatically triggered on every build but you can change this if you want
The lambda code needs packaging in a zip file with a package, from https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/rds-lambda-tutorial.html#vpc-rds-update-function (the lambda code is not the same as we use here)
Otherwise, google how to make a lambda layer using CDK and a zip file created on an EC2
The code looks like this it uses a credential CDK puts in AWS secrets manager:
The lambda logs to CloudWatch:
The AWS region in the lambda may be different to yours
You will have to write the SQL as you want it