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

EC2, Enable authentication using default credential chain #3

Open
wants to merge 2 commits 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: 10 additions & 5 deletions provision/ec2.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,17 @@ type EC2Provisioner struct {
ec2Provisioner *ec2.EC2
}

// NewEC2Provisioner creates an EC2Provisioner and initialises an EC2 client
// NewEC2Provisioner creates an EC2Provisioner and initialises an EC2 client,
// when accessKey and secretKey are "" default credential chain is used
func NewEC2Provisioner(region, accessKey, secretKey string) (*EC2Provisioner, error) {
sess, err := session.NewSession(&aws.Config{
Region: aws.String(region),
Credentials: credentials.NewStaticCredentials(accessKey, secretKey, ""),
})
awsConfig := &aws.Config{Region: aws.String(region)}

if accessKey != "" && secretKey != "" {
awsConfig.Credentials = credentials.NewStaticCredentials(accessKey, secretKey, "")
}

sess, err := session.NewSession(awsConfig)

svc := ec2.New(sess)
return &EC2Provisioner{ec2Provisioner: svc}, err
}
Expand Down