forked from timescale/tsbs
/
aws_session.go
34 lines (31 loc) · 976 Bytes
/
aws_session.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
package timestream
import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"golang.org/x/net/http2"
"net"
"net/http"
"time"
)
func OpenAWSSession(awsRegion *string, timeout time.Duration) (*session.Session, error) {
tr := &http.Transport{
ResponseHeaderTimeout: 20 * time.Second,
// Using DefaultTransport values for other parameters: https://golang.org/pkg/net/http/#RoundTripper
Proxy: http.ProxyFromEnvironment,
DialContext: (&net.Dialer{
KeepAlive: 30 * time.Second,
Timeout: timeout,
}).DialContext,
MaxIdleConns: 100,
IdleConnTimeout: 90 * time.Second,
TLSHandshakeTimeout: 10 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
}
if err := http2.ConfigureTransport(tr); err != nil {
panic("could not configure http transport: " + err.Error())
}
return session.NewSession(&aws.Config{
Region: awsRegion,
MaxRetries: aws.Int(10),
HTTPClient: &http.Client{Transport: tr}})
}