Skip to content

Package for scanning DynamoDb tables in parallel.

License

Notifications You must be signed in to change notification settings

stroeer/ddb-scanner

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ddb-scanner

Package for scanning DynamoDb tables in parallel. This is an updated version of https://github.com/clearbit/go-ddb

install

go get github.com/stroeer/ddb-scanner

use

const (
	region = "eu-west-1"
)

type item struct {
	Pk string
}

func main() {
	cfg, err := config.LoadDefaultConfig(context.TODO(), config.WithRegion(region))

	if err != nil {
		log.Fatal(err)
	}

	sc := scanner.New(scanner.Config{
		Svc:                  dynamodb.NewFromConfig(cfg),
		ProjectionExpression: aws.String("pk"),
		Region:               aws.String(region),
		TableName:            aws.String("test"),
		TotalSegments:        aws.Int32(20),
	})

	start := time.Now()
	sc.Start(scanner.HandlerFunc(func(ddbItems []map[string]types.AttributeValue) {
		var items []item
		err := attributevalue.UnmarshalListOfMaps(ddbItems, &items)
		if err != nil {
			log.Fatalf("failed to unmarshal ddbItems, %v", err)
		}
		for _, i := range items {
			log.Printf("pk: %s\n", i.Pk)
		}
	}))
	log.Printf("table scan finished - count: %d, segments: %d, duration: %s\n", sc.CompletedItems.Value(), sc.CompletedSegments.Value(), time.Since(start))
}

About

Package for scanning DynamoDb tables in parallel.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages