forked from qhenkart/gosqs
/
session_provider.go
46 lines (34 loc) · 1.2 KB
/
session_provider.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
package example
import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/outwatchnz/gosqs"
)
func main_with_session_provider() {
// implement a custom AWS session provider function
provider := func(c gosqs.Config) (*session.Session, error) {
// note: this implementation just hardcodes key and secret, but it could do anything
creds := credentials.NewStaticCredentials("mykey", "mysecret", "")
_, err := creds.Get()
if err != nil {
return nil, gosqs.ErrInvalidCreds.Context(err)
}
cfg := aws.NewConfig().WithRegion("us-west-1").WithCredentials(creds)
hostname := "http://localhost:4150"
cfg.Endpoint = &hostname
return session.NewSession(cfg)
}
// create the gosqs Config with our custom SessionProviderFunc
c := gosqs.Config{
// for emulation only
// Hostname: "http://localhost:4150",
SessionProvider: provider,
TopicARN: "arn:aws:sns:local:000000000000:dispatcher",
Region: "us-west-1",
}
//follows the flow to see how a worker should be configured and operate
initWorker(c)
//follows the flow to see how an http service should be configured and operate
initService(c)
}