Skip to content

Commit c334b85

Browse files
authored
Merge pull request #28 from oreillymedia/CL-627-dynamodb-backup
CL-627 | Add DynamoDBBackup module
2 parents 278d2ff + e30c224 commit c334b85

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

resources/dynamodb-backups.go

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package resources
2+
3+
import (
4+
"github.com/aws/aws-sdk-go/aws"
5+
"github.com/aws/aws-sdk-go/aws/session"
6+
"github.com/aws/aws-sdk-go/service/dynamodb"
7+
"github.com/rebuy-de/aws-nuke/v2/pkg/types"
8+
)
9+
10+
type DynamoDBBackup struct {
11+
svc *dynamodb.DynamoDB
12+
id string
13+
}
14+
15+
func init() {
16+
register("DynamoDBBackup", ListDynamoDBBackups)
17+
}
18+
19+
func ListDynamoDBBackups(sess *session.Session) ([]Resource, error) {
20+
svc := dynamodb.New(sess)
21+
22+
resources := make([]Resource, 0)
23+
24+
var lastEvaluatedBackupArn *string
25+
26+
for {
27+
backupsResp, err := svc.ListBackups(&dynamodb.ListBackupsInput{
28+
ExclusiveStartBackupArn: lastEvaluatedBackupArn,
29+
})
30+
if err != nil {
31+
return nil, err
32+
}
33+
34+
for _, backup := range backupsResp.BackupSummaries {
35+
resources = append(resources, &DynamoDBBackup{
36+
svc: svc,
37+
id: *backup.BackupArn,
38+
})
39+
}
40+
41+
if backupsResp.LastEvaluatedBackupArn == nil {
42+
break
43+
}
44+
45+
lastEvaluatedBackupArn = backupsResp.LastEvaluatedBackupArn
46+
}
47+
48+
return resources, nil
49+
}
50+
51+
func (i *DynamoDBBackup) Remove() error {
52+
params := &dynamodb.DeleteBackupInput{
53+
BackupArn: aws.String(i.id),
54+
}
55+
56+
_, err := i.svc.DeleteBackup(params)
57+
if err != nil {
58+
return err
59+
}
60+
61+
return nil
62+
}
63+
64+
func (i *DynamoDBBackup) Properties() types.Properties {
65+
properties := types.NewProperties()
66+
properties.Set("Identifier", i.id)
67+
68+
return properties
69+
}
70+
71+
func (i *DynamoDBBackup) String() string {
72+
return i.id
73+
}

0 commit comments

Comments
 (0)