dynamodb

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 15, 2021 License: Apache-2.0 Imports: 13 Imported by: 1

README

DynamoDB

A leaky bucket backed by AWS DynamoDB

Usage

This library assumes the table is created with the following attributes:

  • name is the primary key
  • (optional) _ttl is the enabled time to live specification field

Depending on your use case it may be worth disabling the default retries in the passed in aws.Config object. Please refer to the following sections for examples.

CloudFormation Table Definition Example
  Buckets:
    Type: AWS::DynamoDB::Table
    Properties:
      AttributeDefinitions:
      - AttributeName: name
        AttributeType: S
      BillingMode: PAY_PER_REQUEST
      KeySchema:
      - AttributeName: name
        KeyType: HASH
      SSESpecification:
        SSEEnabled: true
      TableName: your-favorite-table-naming-strategy-Buckets
      TimeToLiveSpecification:
        AttributeName: _ttl
        Enabled: true
Usage Example
package main

import (
    "log"
    "time"

    leakybucketDynamoDB "github.com/Clever/leakybucket/dynamodb"

    "github.com/aws/aws-sdk-go/aws"
    "github.com/aws/aws-sdk-go/aws/session"
)

func main() {
    storage, err := leakybucketDynamoDB.New(
        "buckets-table",
        session.New(&aws.Config{
            Region:     aws.String("us-west-1"),
            MaxRetries: aws.Int(0),
        }),
        24*time.Hour,
    )
    if err != nil {
        log.Fatal(err)
    }

    bucket, err := storage.Create("my-bucket", 100, time.Minute)
    if err != nil {
        log.Fatal(err)
    }

    // use your new leaky bucket!
}
Testing

All tests assume there is a locally running DynamoDB defined in an environment variable AWS_DYNAMO_ENDPOINT

Helpful Development Resources

Documentation

Overview

Package dynamodb provides a leaky bucket implementation backed by AWS DynamoDB

For additional details please refer to: https://github.com/Clever/leakybucket/tree/master/dynamodb

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Storage

type Storage struct {
	// contains filtered or unexported fields
}

Storage is a dyanamodb-based, thread-safe leaky bucket factory.

func New

func New(tableName string, s *session.Session, itemTTL time.Duration) (*Storage, error)

New initializes the a new bucket storage factory backed by dynamodb. We recommend the session is configured with minimal or no retries for a real time use case. Additionally, we recommend itemTTL >>> any rate provided in Storage.Create

func (*Storage) Create

func (s *Storage) Create(name string, capacity uint, rate time.Duration) (leakybucket.Bucket, error)

Create a bucket. It will determine the current state of the bucket based on: - The corresponding bucket in the database - From scratch using the values provided

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL