Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add custom http client to helpers aws session #384 #391

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions pkg/common/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"crypto/x509"
"fmt"
"hash"
"net/http"
"os"
"time"

Expand All @@ -33,11 +34,20 @@ import (
// using the standard auth flow. We also have the ability to pass a role ARN
// to allow for roles to be assumed in cross-account access flows.
func GetAWSSession(region string, roleARN string, endpoint string) (sess *session.Session, cfg *aws.Config, accountID *string, err error) {
httpClient := &http.Client{
Transport: &http.Transport{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can do the same thing as in the HTTP target and just slightly tweak default transport, like:

	transport := http.DefaultTransport.(*http.Transport).Clone()
	transport.MaxIdleConnsPerHost = transport.MaxIdleConns
	httpClient := &http.Client{
		Transport: transport,
	}

so to bump per host and make it equal to the total limit. I think we don't have to make it fully configurable.

MaxIdleConns: 100, // Maximum number of idle connections
IdleConnTimeout: 90 * time.Second,
MaxIdleConnsPerHost: 10, // Maximum idle connections per host
},
}

sess = session.Must(session.NewSessionWithOptions(session.Options{
SharedConfigState: session.SharedConfigEnable,
Config: aws.Config{
Region: aws.String(region),
Endpoint: aws.String(endpoint),
Region: aws.String(region),
Endpoint: aws.String(endpoint),
HTTPClient: httpClient,
},
}))

Expand All @@ -46,6 +56,7 @@ func GetAWSSession(region string, roleARN string, endpoint string) (sess *sessio
cfg = &aws.Config{
Credentials: creds,
Region: aws.String(region),
HTTPClient: httpClient,
}
}

Expand Down