/
aws.go
62 lines (54 loc) · 1.95 KB
/
aws.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package libaws
import (
"os"
"sync"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/service/dynamodb"
"github.com/aws/aws-sdk-go/service/kinesis"
dynamoEntyty "github.com/sofyan48/rll-daemon-new/src/entity/http/v1"
)
// Aws ...
type Aws struct {
}
// AwsHAndler ..
func AwsHAndler() *Aws {
return &Aws{}
}
// AwsInterface ...
type AwsInterface interface {
// dynamo
InputDynamo(itemDynamo *dynamoEntyty.DynamoItem, wg *sync.WaitGroup) (*dynamodb.PutItemOutput, error)
UpdateDynamo(ID, status, data string, history *dynamoEntyty.HistoryItem) (*dynamodb.UpdateItemOutput, error)
GetDynamoData(ID string) (*dynamodb.GetItemOutput, error)
GetDynamoHistory(receiverAddress string) (*dynamodb.ScanOutput, error)
// kinesis
WaitUntil(*kinesis.DescribeStreamInput) error
WaitUntilNotExist(data *kinesis.DescribeStreamInput) error
SendStart(ID string, itemDynamo *dynamoEntyty.DynamoItem, stack string, wg *sync.WaitGroup)
Send(data []byte, stack string, wg *sync.WaitGroup) (*kinesis.PutRecordOutput, error)
GetShardIterator() (string, error)
Consumer(data *kinesis.GetRecordsInput) (*kinesis.GetRecordsOutput, error)
GetDescribeInput() *kinesis.DescribeStreamInput
Describe(data *kinesis.DescribeStreamInput) (*kinesis.DescribeStreamOutput, error)
}
// Sessions ...
// @cfg: *entity.AwsConfig
func (aw *Aws) Sessions() *aws.Config {
creds := credentials.NewStaticCredentials(
os.Getenv("AWS_ACCESS_KEY"),
os.Getenv("AWS_ACCESS_SECRET"), "")
creds.Get()
cfgAws := aws.NewConfig().WithRegion(os.Getenv("AWS_ACCESS_AREA")).WithCredentials(creds)
return cfgAws
}
// SessionsKinesis ...
// @cfg: *entity.AwsConfig
func (aw *Aws) SessionsKinesis() *aws.Config {
creds := credentials.NewStaticCredentials(
os.Getenv("AWS_ACCESS_KEY_KINESIS"),
os.Getenv("AWS_ACCESS_SECRET_KINESIS"), "")
creds.Get()
cfgAws := aws.NewConfig().WithRegion(os.Getenv("AWS_ACCESS_AREA")).WithCredentials(creds)
return cfgAws
}