Skip to content
This repository has been archived by the owner on May 16, 2023. It is now read-only.

Commit

Permalink
Merge pull request #26 from danmx/profile-region
Browse files Browse the repository at this point in the history
Fixing loading config for specific profile
  • Loading branch information
danmx authored Apr 16, 2019
2 parents ebf5a67 + 328b39a commit 9bd65c0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
15 changes: 9 additions & 6 deletions pkg/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
remoteSession "github.com/danmx/sigil/pkg/session"

"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/ec2"
"github.com/aws/aws-sdk-go/service/ssm"
Expand Down Expand Up @@ -62,15 +61,19 @@ func Start(input *StartInput) error {
format: input.OutputFormat,
Instances: instanceList,
}
if *input.AWSProfile != "" {
// https://docs.aws.amazon.com/sdk-for-go/v1/developer-guide/configuring-sdk.html
os.Setenv("AWS_PROFILE", *input.AWSProfile)
os.Setenv("AWS_SDK_LOAD_CONFIG", "true")
log.WithFields(log.Fields{
"AWS_PROFILE": os.Getenv("AWS_PROFILE"),
"AWS_SDK_LOAD_CONFIG": os.Getenv("AWS_SDK_LOAD_CONFIG"),
}).Debug("Set Profile env")
}
awsConfig := aws.NewConfig()
if *input.AWSRegion != "" {
awsConfig.Region = input.AWSRegion
}
if *input.AWSProfile != "" {
// Leaving empty filename because of
// https://github.com/aws/aws-sdk-go/blob/704cb4634ea23d666b1046363639d44234fb4ed2/aws/credentials/shared_credentials_provider.go#L31
awsConfig.Credentials = credentials.NewSharedCredentials("", *input.AWSProfile)
}
sess := session.Must(session.NewSession(awsConfig))
// Get the list of instances
ssmDescribeInstancesInput := &ssm.DescribeInstanceInformationInput{}
Expand Down
15 changes: 9 additions & 6 deletions pkg/session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"os/exec"

"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/ec2"
"github.com/aws/aws-sdk-go/service/ssm"
Expand All @@ -24,15 +23,19 @@ type StartInput struct {

// Start will start a session in chosen EC2 instance
func Start(input *StartInput) error {
if *input.AWSProfile != "" {
// https://docs.aws.amazon.com/sdk-for-go/v1/developer-guide/configuring-sdk.html
os.Setenv("AWS_PROFILE", *input.AWSProfile)
os.Setenv("AWS_SDK_LOAD_CONFIG", "true")
log.WithFields(log.Fields{
"AWS_PROFILE": os.Getenv("AWS_PROFILE"),
"AWS_SDK_LOAD_CONFIG": os.Getenv("AWS_SDK_LOAD_CONFIG"),
}).Debug("Set Profile env")
}
awsConfig := aws.NewConfig()
if *input.AWSRegion != "" {
awsConfig.Region = input.AWSRegion
}
if *input.AWSProfile != "" {
// Leaving empty filename because of
// https://github.com/aws/aws-sdk-go/blob/704cb4634ea23d666b1046363639d44234fb4ed2/aws/credentials/shared_credentials_provider.go#L31
awsConfig.Credentials = credentials.NewSharedCredentials("", *input.AWSProfile)
}
sess := session.Must(session.NewSession(awsConfig))
var instanceID *string
switch *input.TargetType {
Expand Down

0 comments on commit 9bd65c0

Please sign in to comment.