This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| functions: | |
| manual-backup: | |
| handler: rds-clone-snap.main | |
| timeout: 15 | |
| events: | |
| - schedule: cron(0 10 1/1 * ? *) | |
| manual-backup-other-region: | |
| handler: rds-clone-snap-region.main | |
| timeout: 15 | |
| events: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package: | |
| exclude: | |
| - README.md | |
| - .gitignore | |
| - .vscode | |
| - node_modules | |
| - __test__ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| provider: | |
| name: aws | |
| runtime: nodejs10.x | |
| region: us-west-2 | |
| profile: <YOUR-AWS-PROFILE> | |
| iamManagedPolicies: | |
| - "arn:aws:iam::aws:policy/AmazonRDSFullAccess" | |
| environment: | |
| daysBefore: 30 | |
| keepDays: 6 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var cluster = await rdsFunc.describeClusters(); | |
| for (i=0;i<cluster.length;i++){ | |
| var snaps = await rdsFunc.describeClustersAutomatedSnapshot(cluster[i].DBClusterIdentifier) | |
| if(snaps){ | |
| snaps.forEach(async (snap)=>{ | |
| AWS.config.update({ | |
| region: process.env.copyRegion | |
| }) | |
| var rdsFuncOtherRegion = new RDSFunc(AWS) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var cluster = await rdsFunc.describeClusters(); | |
| cluster.forEach(async (cluster)=>{ | |
| var snaps = await rdsFunc.describeClustersManualSnapshot(cluster.DBClusterIdentifier) | |
| if(snaps){ | |
| snaps.forEach(async (snap)=>{ | |
| var copyDate = dateFunc.minusDaysFromToday(daysBefore); | |
| var snapshotDate = dateFunc.removeTimeFromDate(snap.SnapshotCreateTime); | |
| if (copyDate == snapshotDate) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var cluster = await rdsFunc.describeClusters(); | |
| cluster.forEach(async (cluster)=>{ | |
| var snaps = await rdsFunc.describeClustersAutomatedSnapshot(cluster.DBClusterIdentifier) | |
| if(snaps){ | |
| snaps.forEach(async (snap)=>{ | |
| var copyDate = dateFunc.minusDaysFromToday(daysBefore); | |
| var snapshotDate = dateFunc.removeTimeFromDate(snap.SnapshotCreateTime); | |
| if (copyDate == snapshotDate) { | |
| var copy = await rdsFunc.copyClusterSnapshot(snap.DBClusterSnapshotIdentifier) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const defaultTag = { | |
| Key: 'ClonedBy', | |
| Value: 'Lambda' | |
| } | |
| const regionTag = { Key: 'SourceRegion',Value: ''} | |
| class RDSFunc{ | |
| constructor(AWS) { | |
| this.rds = new AWS.RDS(); | |
| } | |
| describeClusters(){ |