Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CL-627 | Add DynamoDBBackup module #28

Merged
merged 1 commit into from
Jul 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
Loading