Documentation ¶
Index ¶
- Constants
- Variables
- func GzipStr(raw string) (*bytes.Buffer, error)
- func MustGzipStr(raw string) []byte
- func MustGzipStrToStr(raw string) string
- func MustNewDefaultConfig() aws.Config
- func NewAwsConfig(ak, sk, region string) (aws.Config, error)
- func QueueNameNotMatchError(msg string) error
- type DynamodbWrapper
- func (w *DynamodbWrapper) AddItem(data interface{}) error
- func (w *DynamodbWrapper) AddItemBatch(data []types.WriteRequest) (int, error)
- func (w *DynamodbWrapper) BuildAttrValueMap(keys []string, values []interface{}) (map[string]types.AttributeValue, error)
- func (w *DynamodbWrapper) BuildQueryExpr(name string, key interface{}) (expression.Expression, error)
- func (w *DynamodbWrapper) BuildScanExpr()
- func (w *DynamodbWrapper) BuildTableInput(primaryKey string, sortKey string, skType types.ScalarAttributeType) *dynamodb.CreateTableInput
- func (w *DynamodbWrapper) CreateTable(tableInput *dynamodb.CreateTableInput) (*types.TableDescription, error)
- func (w *DynamodbWrapper) DeleteRow(key map[string]types.AttributeValue) error
- func (w *DynamodbWrapper) DeleteTable() error
- func (w *DynamodbWrapper) ListTables() ([]string, error)
- func (w *DynamodbWrapper) Query(expr expression.Expression, out interface{}) error
- func (w *DynamodbWrapper) Retrieve(key map[string]types.AttributeValue, out interface{}) error
- func (w *DynamodbWrapper) Scan(expr expression.Expression, out interface{}) error
- func (w *DynamodbWrapper) TableExists() (bool, error)
- type EventWrapper
- type FunctionWrapper
- func (w *FunctionWrapper) Create(functionName string, handlerName string, iamRoleArn *string, data []byte) types.State
- func (w *FunctionWrapper) GetConfig() (*types.FunctionConfiguration, error)
- func (w *FunctionWrapper) Invoke(payload []byte, getLog bool, asyncMode bool) (*lambda.InvokeOutput, error)
- func (w *FunctionWrapper) InvokeAsync(payload []byte, getLog bool) (*lambda.InvokeOutput, error)
- func (w *FunctionWrapper) InvokeSync(payload []byte, getLog bool) (*lambda.InvokeOutput, error)
- func (w *FunctionWrapper) List(maxItems int) ([]types.FunctionConfiguration, error)
- func (w *FunctionWrapper) PrintInvokeOutput(output *lambda.InvokeOutput)
- type OpensearchWrapper
- type Roles
- type S3OptionFunc
- func WithBucket(s string) S3OptionFunc
- func WithEmptyFile(b bool) S3OptionFunc
- func WithFolderLevel(n int) S3OptionFunc
- func WithGz(b bool) S3OptionFunc
- func WithMaxKeys(n int) S3OptionFunc
- func WithSaveTo(s string) S3OptionFunc
- func WithSavedName(s string) S3OptionFunc
- func WithTimeout(n int) S3OptionFunc
- type S3Options
- type S3Wrapper
- func (w *S3Wrapper) Download(objectKey string, opts ...S3OptionFunc) string
- func (w *S3Wrapper) DownloadFile(objectKey string, fileName string) error
- func (w *S3Wrapper) IsExisted(objectKey string) (bool, error)
- func (w *S3Wrapper) ListBuckets() (*s3.ListBucketsOutput, error)
- func (w *S3Wrapper) ListObjects(prefix string, opts ...S3OptionFunc) ([]string, error)
- func (w *S3Wrapper) MustUpload(localFile, s3path string)
- func (w *S3Wrapper) MustUploadRawData(raw string, objectKey string, opts ...S3OptionFunc)
- func (w *S3Wrapper) Upload(localFile, s3path string) (*manager.UploadOutput, error)
- func (w *S3Wrapper) UploadLargeObject(bucketName string, objectKey string, largeObject []byte) error
- func (w *S3Wrapper) UploadRawData(raw, objectKey string, opts ...S3OptionFunc) error
- func (w *S3Wrapper) UploadRawDataToGz(raw string, objectKey string) error
- func (w *S3Wrapper) UploadToBucket(localFile, bucket, s3path string) (*manager.UploadOutput, error)
- type SchedulerWrapper
- func (w *SchedulerWrapper) Create(name, schedule, targetArn, roleArn, jsonStr string) error
- func (w *SchedulerWrapper) DeleteSchedule(name string) (*scheduler.DeleteScheduleOutput, error)
- func (w *SchedulerWrapper) Disable(name string, schedule, targetArn, roleArn, jsonStr string) error
- func (w *SchedulerWrapper) ListSchedulers(name string) (*scheduler.ListSchedulesOutput, error)
- func (w *SchedulerWrapper) Update(name string, schedule, targetArn, roleArn, jsonStr string) error
- func (w *SchedulerWrapper) Upsert(name string, schedule, targetArn, roleArn, jsonStr string) error
- type SqsOptFunc
- type SqsOpts
- type SqsResp
- type SqsWrapper
- func (w *SqsWrapper) CheckRole(least Roles) error
- func (w *SqsWrapper) CreateQueue(name string) (string, error)
- func (w *SqsWrapper) DeleteMsg(handle *string) (*sqs.DeleteMessageOutput, error)
- func (w *SqsWrapper) DeleteQueue(name string) error
- func (w *SqsWrapper) GetMsg() (*sqs.ReceiveMessageOutput, error)
- func (w *SqsWrapper) GetMsgs(opts ...SqsOptFunc) (*sqs.ReceiveMessageOutput, error)
- func (w *SqsWrapper) GetQueueUrl(name string) (string, error)
- func (w *SqsWrapper) GetQueues() (*sqs.ListQueuesOutput, error)
- func (w *SqsWrapper) GetRemainedItems(opts ...SqsOptFunc) (int64, error)
- func (w *SqsWrapper) GoReadMessages(ch chan *SqsResp, opts ...SqsOptFunc)
- func (w *SqsWrapper) MustDeleteMsg(handle *string) *sqs.DeleteMessageOutput
- func (w *SqsWrapper) MustGetMsg() *types.Message
- func (w *SqsWrapper) MustGetMsgs(opts ...SqsOptFunc) []*string
- func (w *SqsWrapper) MustGetQueueUrl(name string) string
- func (w *SqsWrapper) MustSendMsg(message string) *sqs.SendMessageOutput
- func (w *SqsWrapper) MustSendMsgByRetry(message string, retries uint) *sqs.SendMessageOutput
- func (w *SqsWrapper) ReadMessages(chanResp chan *SqsResp, opts ...SqsOptFunc)
- func (w *SqsWrapper) SendMsg(message string) (*sqs.SendMessageOutput, error)
- func (w *SqsWrapper) SendMsgBatch(messages []string) (*sqs.SendMessageBatchOutput, error)
- func (w *SqsWrapper) SetQueueUrl(name string)
Examples ¶
Constants ¶
const ( TypeN = types.ScalarAttributeTypeN TypeS = types.ScalarAttributeTypeS TypeB = types.ScalarAttributeTypeB )
const ( READ_SQS_ERROR = iota READ_SQS_OK READ_SQS_ALL READ_SQS_MAXIMUM )
Variables ¶
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") )
var ErrGzSuffixRequired = errors.New("non gz format: .gz is required")
Functions ¶
func MustGzipStr ¶
func MustGzipStrToStr ¶
func MustNewDefaultConfig ¶
func NewAwsConfig ¶
Example ¶
_, err := NewAwsConfig("ak", "sk", "region") fmt.Println(err == nil)
Output: true
func QueueNameNotMatchError ¶
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 NewFunctionWrapperWithDefaultConfig ¶
func NewFunctionWrapperWithDefaultConfig(funcName string, dryRun bool) (*FunctionWrapper, error)
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 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 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 ¶
DownloadFile gets an object from a bucket and stores it in a local file.
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 ¶
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 (*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.
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 SqsResp ¶
func NewSqsResp ¶
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 ¶
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)