Skip to content

Instantly share code, notes, and snippets.

View krismorte's full-sized avatar
💭
studying and coding, coding and studying again and again and agin 😄

Krisnamourt Filho krismorte

💭
studying and coding, coding and studying again and again and agin 😄
View GitHub Profile
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:
package:
exclude:
- README.md
- .gitignore
- .vscode
- node_modules
- __test__
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
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)
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) {
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)
const defaultTag = {
Key: 'ClonedBy',
Value: 'Lambda'
}
const regionTag = { Key: 'SourceRegion',Value: ''}
class RDSFunc{
constructor(AWS) {
this.rds = new AWS.RDS();
}
describeClusters(){