Skip to content

Commit

Permalink
Merge pull request #28 from oreillymedia/CL-627-dynamodb-backup
Browse files Browse the repository at this point in the history
CL-627 | Add DynamoDBBackup module
  • Loading branch information
gsoria authored Jul 9, 2024
2 parents 278d2ff + e30c224 commit c334b85
Showing 1 changed file with 73 additions and 0 deletions.
73 changes: 73 additions & 0 deletions resources/dynamodb-backups.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package resources

import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/dynamodb"
"github.com/rebuy-de/aws-nuke/v2/pkg/types"
)

type DynamoDBBackup struct {
svc *dynamodb.DynamoDB
id string
}

func init() {
register("DynamoDBBackup", ListDynamoDBBackups)
}

func ListDynamoDBBackups(sess *session.Session) ([]Resource, error) {
svc := dynamodb.New(sess)

resources := make([]Resource, 0)

var lastEvaluatedBackupArn *string

for {
backupsResp, err := svc.ListBackups(&dynamodb.ListBackupsInput{
ExclusiveStartBackupArn: lastEvaluatedBackupArn,
})
if err != nil {
return nil, err
}

for _, backup := range backupsResp.BackupSummaries {
resources = append(resources, &DynamoDBBackup{
svc: svc,
id: *backup.BackupArn,
})
}

if backupsResp.LastEvaluatedBackupArn == nil {
break
}

lastEvaluatedBackupArn = backupsResp.LastEvaluatedBackupArn
}

return resources, nil
}

func (i *DynamoDBBackup) Remove() error {
params := &dynamodb.DeleteBackupInput{
BackupArn: aws.String(i.id),
}

_, err := i.svc.DeleteBackup(params)
if err != nil {
return err
}

return nil
}

func (i *DynamoDBBackup) Properties() types.Properties {
properties := types.NewProperties()
properties.Set("Identifier", i.id)

return properties
}

func (i *DynamoDBBackup) String() string {
return i.id
}

0 comments on commit c334b85

Please sign in to comment.