-
Notifications
You must be signed in to change notification settings - Fork 0
/
aws.go
36 lines (33 loc) · 982 Bytes
/
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
package fargate
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/aws/aws-sdk-go/service/sts"
)
func newSession() (*session.Session, error) {
return session.NewSession()
}
//lint:ignore U1000 we will use it in future
func newSessionWithRole(role string) (*session.Session, error) {
defaultSession, err := newSession()
if err != nil {
return nil, err
}
svc := sts.New(defaultSession)
result, err := svc.AssumeRole(&sts.AssumeRoleInput{
DurationSeconds: aws.Int64(900),
RoleArn: aws.String(role),
RoleSessionName: aws.String("bent"),
})
if err != nil {
return nil, err
}
return session.NewSession(&aws.Config{
Credentials: credentials.NewStaticCredentialsFromCreds(credentials.Value{
AccessKeyID: *result.Credentials.AccessKeyId,
SecretAccessKey: *result.Credentials.SecretAccessKey,
SessionToken: *result.Credentials.SessionToken,
}),
})
}