Documentation ¶
Index ¶
- func AcquireLock(options *Options) error
- func GetLockStatus(options *Options) (*dynamodb.GetItemOutput, error)
- func NewAuthenticatedSession(awsRegion string) (*session.Session, error)
- func NewDynamoDb(awsRegion string) (*dynamodb.DynamoDB, error)
- func ReleaseLock(options *Options) error
- type Options
- type TableNotActiveError
- type TimeoutExceeded
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AcquireLock ¶
AcquireLock will attempt to acquire a lock in DynamoDB table while taking the configuration options into account. We are using DynamoDB to create a table to help us track the lock status of different resources. The acquiring of a lock attempts to create a table. The intention is that we have 1 table per resource in a single region. This would allow the locking mechanism to flexibly decide if a resource is locked or not. For test cases where the AWS resource is multi-region, or global, the configuration of which regions to use should reflect that.
func GetLockStatus ¶
func GetLockStatus(options *Options) (*dynamodb.GetItemOutput, error)
GetLockStatus attempts to acquire the lock and check if the expected item is there If there's the expected Item with the correct `LockString` value - then the status is `locked`, if the item is not there - then the status is `not locked`
func NewAuthenticatedSession ¶
NewAuthenticatedSession gets an AWS Session, checking that the user has credentials properly configured in their environment
func NewDynamoDb ¶
NewDynamoDb returns an authenticated client object for accessing DynamoDb
func ReleaseLock ¶
ReleaseLock will attempt to release the lock defined by the provided lock string in the configured lock table for the configured region
Types ¶
type Options ¶
type Options struct { // The AWS region for which you wish to create the distributed lock for. For example, if set to `us-east-1`, // the lock will create a DynamoDB table and record for the AWS resource (e.g. Security Hub) in the same region to mark it as locked. // This means if the same AWS resource (Security Hub) is then reference from a different part of the system, also using this lock mechanism, // the resource will appear as it's locked already and therefore not available to modify. AwsRegion string // The name of the DynamoDB table that will store the lock status for the resource in the given region. LockTable string // The name of the DynamoDB Item value that will store the lock status for the resource in the given region. LockString string // The value for how many times AcquireLock will retry to acquire the lock MaxRetries int // The value for how long AcquireLock will sleep for between retries to get the lock SleepBetweenRetries time.Duration // The logger to use for the lock Logger *logrus.Logger // Custom session to use to authenticate to AWS in the SDK. If nil, constructs the session based on the default // authentication chain in the SDK. AwsSession *session.Session }
type TableNotActiveError ¶
type TableNotActiveError struct {
LockTable string
}
func (TableNotActiveError) Error ¶
func (err TableNotActiveError) Error() string
type TimeoutExceeded ¶
func (TimeoutExceeded) Error ¶
func (err TimeoutExceeded) Error() string