xaws

package module
v0.1.3-20240111 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2024 License: AGPL-3.0 Imports: 38 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const (
	READ_SQS_ERROR = iota
	READ_SQS_OK
	READ_SQS_ALL
	READ_SQS_MAXIMUM
)

Variables

View Source
var (
	ErrRoleViolation = errors.New("role violation: current role is not allowed to perform this operation")
	ErrMessgeEmpty   = errors.New("message is empty")

	ErrQueueNameNotMatch = errors.New("queue name not match")
)
View Source
var ErrGzSuffixRequired = errors.New("non gz format: .gz is required")

Functions

func GzipStr

func GzipStr(raw string) (*bytes.Buffer, error)

func MustGzipStr

func MustGzipStr(raw string) []byte

func MustGzipStrToStr

func MustGzipStrToStr(raw string) string

func MustNewDefaultConfig

func MustNewDefaultConfig() aws.Config

func NewAwsConfig

func NewAwsConfig(ak, sk, region string) (aws.Config, error)
Example
_, err := NewAwsConfig("ak", "sk", "region")
fmt.Println(err == nil)
Output:

true

func QueueNameNotMatchError

func QueueNameNotMatchError(msg string) error

Types

type DynamodbWrapper

type DynamodbWrapper struct {
	Config aws.Config
	Client *dynamodb.Client
	DdbCtx context.Context

	TableName string

	Timeout int
	// contains filtered or unexported fields
}

func NewDynamodbWrapper

func NewDynamodbWrapper(table string, config aws.Config, readCapacity, writeCapacity int) *DynamodbWrapper
Example
cfg, err := NewAwsConfig("ak", "sk", "region")
fmt.Println(err == nil)
cap := 10
w := NewDynamodbWrapper("", cfg, cap, cap)
fmt.Println(w == nil)
Output:

true
false

func (*DynamodbWrapper) AddItem

func (w *DynamodbWrapper) AddItem(data interface{}) error
Example
cfg, _ := NewAwsConfig("ak", "sk", "region")
cap := 10
w := NewDynamodbWrapper("", cfg, cap, cap)
var data interface{}
e := w.AddItem(data)
fmt.Println(e == nil)
Output:

false

func (*DynamodbWrapper) AddItemBatch

func (w *DynamodbWrapper) AddItemBatch(data []types.WriteRequest) (int, error)

func (*DynamodbWrapper) BuildAttrValueMap

func (w *DynamodbWrapper) BuildAttrValueMap(keys []string, values []interface{}) (map[string]types.AttributeValue, error)

func (*DynamodbWrapper) BuildQueryExpr

func (w *DynamodbWrapper) BuildQueryExpr(name string, key interface{}) (expression.Expression, error)

func (*DynamodbWrapper) BuildScanExpr

func (w *DynamodbWrapper) BuildScanExpr()

func (*DynamodbWrapper) BuildTableInput

func (w *DynamodbWrapper) BuildTableInput(primaryKey string, sortKey string, skType types.ScalarAttributeType) *dynamodb.CreateTableInput

func (*DynamodbWrapper) CreateTable

func (w *DynamodbWrapper) CreateTable(tableInput *dynamodb.CreateTableInput) (*types.TableDescription, error)

func (*DynamodbWrapper) DeleteRow

func (w *DynamodbWrapper) DeleteRow(key map[string]types.AttributeValue) error

func (*DynamodbWrapper) DeleteTable

func (w *DynamodbWrapper) DeleteTable() error

func (*DynamodbWrapper) ListTables

func (w *DynamodbWrapper) ListTables() ([]string, error)

ListTables lists the DynamoDB table names for the current account.

func (*DynamodbWrapper) Query

func (w *DynamodbWrapper) Query(expr expression.Expression, out interface{}) error

func (*DynamodbWrapper) Retrieve

func (w *DynamodbWrapper) Retrieve(key map[string]types.AttributeValue, out interface{}) error

func (*DynamodbWrapper) Scan

func (w *DynamodbWrapper) Scan(expr expression.Expression, out interface{}) error

func (*DynamodbWrapper) TableExists

func (w *DynamodbWrapper) TableExists() (bool, error)

TableExists determines whether a DynamoDB table exists.

Example
cfg, _ := NewAwsConfig("ak", "sk", "region")
cap := 10
w := NewDynamodbWrapper("", cfg, cap, cap)
b, e := w.TableExists()
fmt.Println(b)
fmt.Println(e == nil)
Output:

false
false

type EventWrapper

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

func NewEventWrapper

func NewEventWrapper(cfg aws.Config) (*EventWrapper, error)

func NewEventWrapperWithDefaultConfig

func NewEventWrapperWithDefaultConfig() (*EventWrapper, error)

func (*EventWrapper) DeleteRule

func (w *EventWrapper) DeleteRule(name string) error

DeleteRule delete a rule with name.

func (*EventWrapper) ListRules

func (w *EventWrapper) ListRules() []types.Rule

ListRules lists all rules available.

func (*EventWrapper) ListTargets

func (w *EventWrapper) ListTargets(name string)

ListTargets list targets of a rule.

func (*EventWrapper) PutRule

func (w *EventWrapper) PutRule(name string, schedule string) error

PutRule put a rule.

func (*EventWrapper) PutTarget

func (w *EventWrapper) PutTarget(name string, targetArn, targetId, jsonStr string)

PutTarget put target to a rule.

type FunctionWrapper

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

func NewFunctionWrapper

func NewFunctionWrapper(funcName string, dryRun bool, cfg aws.Config) (*FunctionWrapper, error)

func NewFunctionWrapperWithDefaultConfig

func NewFunctionWrapperWithDefaultConfig(funcName string, dryRun bool) (*FunctionWrapper, error)

func (*FunctionWrapper) Create

func (w *FunctionWrapper) Create(functionName string, handlerName string, iamRoleArn *string, data []byte) types.State

func (*FunctionWrapper) GetConfig

func (w *FunctionWrapper) GetConfig() (*types.FunctionConfiguration, error)

GetConfig gets data about function.

func (*FunctionWrapper) Invoke

func (w *FunctionWrapper) Invoke(payload []byte, getLog bool, asyncMode bool) (*lambda.InvokeOutput, error)

func (*FunctionWrapper) InvokeAsync

func (w *FunctionWrapper) InvokeAsync(payload []byte, getLog bool) (*lambda.InvokeOutput, error)

InvokeAsync invokes the function asynchronously.

func (*FunctionWrapper) InvokeSync

func (w *FunctionWrapper) InvokeSync(payload []byte, getLog bool) (*lambda.InvokeOutput, error)

InvokeSync invokes the lambda function specified by name.

func (*FunctionWrapper) List

func (w *FunctionWrapper) List(maxItems int) ([]types.FunctionConfiguration, error)

List lists up to maxItems for account.

func (*FunctionWrapper) PrintInvokeOutput

func (w *FunctionWrapper) PrintInvokeOutput(output *lambda.InvokeOutput)

type OpensearchWrapper

type OpensearchWrapper struct {
	Config aws.Config
	Client *opensearch.Client
}

func NewOpensearchWrapper

func NewOpensearchWrapper() *OpensearchWrapper

func (*OpensearchWrapper) DescribeDomainNodes

func (w *OpensearchWrapper) DescribeDomainNodes(name string) []types.DomainNodesStatus

DescribeNodes

type Roles

type Roles string
const (
	Q_EMPTY    Roles = ""
	Q_C        Roles = "c"   // create
	Q_R        Roles = "r"   // read
	Q_D        Roles = "d"   // delete
	Q_ADMIN    Roles = "crd" // crd
	Q_PRODUCER Roles = "cr"  // cr
	Q_CONSUMER Roles = "rd"  // rd
)

type S3OptionFunc

type S3OptionFunc func(o *S3Options)

func WithBucket

func WithBucket(s string) S3OptionFunc

func WithEmptyFile

func WithEmptyFile(b bool) S3OptionFunc

func WithFolderLevel

func WithFolderLevel(n int) S3OptionFunc

WithFolderLevel is how many level of folder kept from s3uri

func WithGz

func WithGz(b bool) S3OptionFunc

func WithMaxKeys

func WithMaxKeys(n int) S3OptionFunc

func WithSaveTo

func WithSaveTo(s string) S3OptionFunc

func WithSavedName

func WithSavedName(s string) S3OptionFunc

func WithTimeout

func WithTimeout(n int) S3OptionFunc

type S3Options

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

type S3Wrapper

type S3Wrapper struct {
	Config aws.Config
	Client *s3.Client

	Bucket string
	// upload timeout
	Timeout int

	SaveTo string
}

func MustNewS3WrapperWithDefaultConfig

func MustNewS3WrapperWithDefaultConfig(bucket string, opts ...S3OptionFunc) *S3Wrapper

func NewS3Wrapper

func NewS3Wrapper(bucket string, cfg aws.Config, opts ...S3OptionFunc) *S3Wrapper
Example
cfg, err := NewAwsConfig("ak", "sk", "region")
fmt.Println(err == nil)
s3 := NewS3Wrapper("test", cfg)
fmt.Println(s3 == nil)
Output:

true
false

func NewS3WrapperWithDefaultConfig

func NewS3WrapperWithDefaultConfig(bucket string, opts ...S3OptionFunc) (*S3Wrapper, error)

func (*S3Wrapper) Download

func (w *S3Wrapper) Download(objectKey string, opts ...S3OptionFunc) string

Download downloads objectKey to default folder(w.SaveTo) with same name

  • if file existed, directly return the filename

about opt.folderLevel:

  • `-1`: use objectKey
  • `0`: only name
  • else with folders

func (*S3Wrapper) DownloadFile

func (w *S3Wrapper) DownloadFile(objectKey string, fileName string) error

DownloadFile gets an object from a bucket and stores it in a local file.

func (*S3Wrapper) IsExisted

func (w *S3Wrapper) IsExisted(objectKey string) (bool, error)

func (*S3Wrapper) ListBuckets

func (w *S3Wrapper) ListBuckets() (*s3.ListBucketsOutput, error)

func (*S3Wrapper) ListObjects

func (w *S3Wrapper) ListObjects(prefix string, opts ...S3OptionFunc) ([]string, error)

ListObjects list all available objects in bucket with prefix.

@param prefix
@param opts

@return []string: list s3 files found
@return error

func (*S3Wrapper) MustUpload

func (w *S3Wrapper) MustUpload(localFile, s3path string)
Example
cfg, _ := NewAwsConfig("ak", "sk", "region")
s3 := NewS3Wrapper("test", cfg)
s3.MustUpload("local/file", "/s3path/xxx")
Output:

func (*S3Wrapper) MustUploadRawData

func (w *S3Wrapper) MustUploadRawData(raw string, objectKey string, opts ...S3OptionFunc)

UploadRawData uploads and save raw data to s3 object key(no encoding:gzip supported).

func (*S3Wrapper) Upload

func (w *S3Wrapper) Upload(localFile, s3path string) (*manager.UploadOutput, error)
Example
cfg, _ := NewAwsConfig("ak", "sk", "region")
s3 := NewS3Wrapper("test", cfg)
s3.Upload("local/file", "/s3path/xxx")
Output:

func (*S3Wrapper) UploadLargeObject

func (w *S3Wrapper) UploadLargeObject(bucketName string, objectKey string, largeObject []byte) error

UploadLargeObject uses an upload manager to upload data to an object in a bucket. The upload manager breaks large data into parts and uploads the parts concurrently.

func (*S3Wrapper) UploadRawData

func (w *S3Wrapper) UploadRawData(raw, objectKey string, opts ...S3OptionFunc) error

func (*S3Wrapper) UploadRawDataToGz

func (w *S3Wrapper) UploadRawDataToGz(raw string, objectKey string) error

func (*S3Wrapper) UploadToBucket

func (w *S3Wrapper) UploadToBucket(localFile, bucket, s3path string) (*manager.UploadOutput, error)

type SchedulerWrapper

type SchedulerWrapper struct {
	GroupName string
	// contains filtered or unexported fields
}

https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-run-lambda-schedule.html https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/scheduler/client/create_schedule.html

func NewSchedulerWrapper

func NewSchedulerWrapper(groupName string) (*SchedulerWrapper, error)

func (*SchedulerWrapper) Create

func (w *SchedulerWrapper) Create(name, schedule, targetArn, roleArn, jsonStr string) error

Create create a scheduler.

func (*SchedulerWrapper) DeleteSchedule

func (w *SchedulerWrapper) DeleteSchedule(name string) (*scheduler.DeleteScheduleOutput, error)

DeleteSchedule delete a schedule.

func (*SchedulerWrapper) Disable

func (w *SchedulerWrapper) Disable(name string, schedule, targetArn, roleArn, jsonStr string) error

func (*SchedulerWrapper) ListSchedulers

func (w *SchedulerWrapper) ListSchedulers(name string) (*scheduler.ListSchedulesOutput, error)

ListSchedulers list.

func (*SchedulerWrapper) Update

func (w *SchedulerWrapper) Update(name string, schedule, targetArn, roleArn, jsonStr string) error

Update updates a scheduler.

func (*SchedulerWrapper) Upsert

func (w *SchedulerWrapper) Upsert(name string, schedule, targetArn, roleArn, jsonStr string) error

Upsert create or update a scheduler.

type SqsOptFunc

type SqsOptFunc func(o *SqsOpts)

func WithBatch

func WithBatch(i int) SqsOptFunc

func WithMax

func WithMax(i int) SqsOptFunc

func WithQueueName

func WithQueueName(s string) SqsOptFunc

func WithReceiveTimeSeconds

func WithReceiveTimeSeconds(i int) SqsOptFunc

type SqsOpts

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

type SqsResp

type SqsResp struct {
	Type int
	Msg  *string
}

func NewSqsResp

func NewSqsResp(msg *string, t int) *SqsResp

type SqsWrapper

type SqsWrapper struct {
	Config aws.Config
	Client *sqs.Client

	// upload timeout
	Timeout int

	QueueName string
	QueueUrl  string

	BatchSize int
	SendCache []string

	Role Roles
	// contains filtered or unexported fields
}

func NewSqsWrapper

func NewSqsWrapper(queue string, cfg aws.Config, batchSize int, timeout int) *SqsWrapper
Example
cfg, err := NewAwsConfig("ak", "sk", "region")
fmt.Println(err == nil)
sqs := NewSqsWrapper("test", cfg, 1, 60)
fmt.Println(sqs == nil)
Output:

true
false

func NewSqsWrapperWithDefaultConfig

func NewSqsWrapperWithDefaultConfig(queue string, batchSize int) (*SqsWrapper, error)

func (*SqsWrapper) CheckRole

func (w *SqsWrapper) CheckRole(least Roles) error

func (*SqsWrapper) CreateQueue

func (w *SqsWrapper) CreateQueue(name string) (string, error)

func (*SqsWrapper) DeleteMsg

func (w *SqsWrapper) DeleteMsg(handle *string) (*sqs.DeleteMessageOutput, error)

func (*SqsWrapper) DeleteQueue

func (w *SqsWrapper) DeleteQueue(name string) error

func (*SqsWrapper) GetMsg

func (w *SqsWrapper) GetMsg() (*sqs.ReceiveMessageOutput, error)

func (*SqsWrapper) GetMsgs

func (w *SqsWrapper) GetMsgs(opts ...SqsOptFunc) (*sqs.ReceiveMessageOutput, error)

func (*SqsWrapper) GetQueueUrl

func (w *SqsWrapper) GetQueueUrl(name string) (string, error)

GetQueueUrl gets the URL of an Amazon SQS queue Inputs:

queueName is the name of the queue

Output:

If success, the URL of the queue and nil
Otherwise, an empty string and an error from the call to

func (*SqsWrapper) GetQueues

func (w *SqsWrapper) GetQueues() (*sqs.ListQueuesOutput, error)

GetQueues returns a list of queue names

func (*SqsWrapper) GetRemainedItems

func (w *SqsWrapper) GetRemainedItems(opts ...SqsOptFunc) (int64, error)

func (*SqsWrapper) GoReadMessages

func (w *SqsWrapper) GoReadMessages(ch chan *SqsResp, opts ...SqsOptFunc)

func (*SqsWrapper) MustDeleteMsg

func (w *SqsWrapper) MustDeleteMsg(handle *string) *sqs.DeleteMessageOutput

func (*SqsWrapper) MustGetMsg

func (w *SqsWrapper) MustGetMsg() *types.Message

func (*SqsWrapper) MustGetMsgs

func (w *SqsWrapper) MustGetMsgs(opts ...SqsOptFunc) []*string

func (*SqsWrapper) MustGetQueueUrl

func (w *SqsWrapper) MustGetQueueUrl(name string) string

func (*SqsWrapper) MustSendMsg

func (w *SqsWrapper) MustSendMsg(message string) *sqs.SendMessageOutput
Example
cfg, _ := NewAwsConfig("ak", "sk", "region")
sqs := NewSqsWrapper("test", cfg, 1, 60)
sqs.MustSendMsg("test message")
Output:

func (*SqsWrapper) MustSendMsgByRetry

func (w *SqsWrapper) MustSendMsgByRetry(message string, retries uint) *sqs.SendMessageOutput

func (*SqsWrapper) ReadMessages

func (w *SqsWrapper) ReadMessages(chanResp chan *SqsResp, opts ...SqsOptFunc)

func (*SqsWrapper) SendMsg

func (w *SqsWrapper) SendMsg(message string) (*sqs.SendMessageOutput, error)
Example
cfg, _ := NewAwsConfig("ak", "sk", "region")
sqs := NewSqsWrapper("test", cfg, 1, 60)
sqs.SendMsg("test message")
Output:

func (*SqsWrapper) SendMsgBatch

func (w *SqsWrapper) SendMsgBatch(messages []string) (*sqs.SendMessageBatchOutput, error)

func (*SqsWrapper) SetQueueUrl

func (w *SqsWrapper) SetQueueUrl(name string)

Jump to

Keyboard shortcuts

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