Now we limit Event of focus on RDS below. you can see more detail here
RDS-EVENT-0042: Manual snapshot created.
Required ENV config
OPT_SRC_REGION: Insert source region of your snapshot created.
OPT_TARGET_REGION: Insert destination region of your snapshot to copy.
OPT_BEDUG: If provided, lambda should more log level.
OPT_DB_NAME: Insert your RDS DB indentifier(Name) to specify this tasks copy.
OPT_OPTION_GROUP_NAME: Insert your option_group name in destination region to copy.
OPT_KMS_KEY_ID: Insert KMS key(ARN, ID, or Alias) to encrypted snapshot in destination region.
How to build
Preparing a binary to deploy to AWS Lambda requires that it is compiled for Linux and placed into a .zip file.
# Remember to build your handler executable for Linux!
# When using the `provided.al2` runtime, the handler executable should be named `bootstrap`
GOOS=linux GOARCH=amd64 go build -o hello main.go
zip lambda-handler.zip hello
Or you can use Taskfile to automate the previous command.
task build
Build and push to S3
You must accessible to AWS cli
Run terraform in folder ./terraform to create S3 bucket before push your a Go binary.
If you create a function in AWS Lambda, you can set up a trigger from AWS EventBridge to capture and filter the Event from RDS to created snapshot.
Then it will execute in nearly time to run a function and gathering snapshot from source and destination region to compared and return unique snapshot that didn't copy to destination region.
The function will try to request AWS API for running the CopyDBSnapshot task.
Any activity, you can see the log from function on STDOUT(also Cloudwatch log).