Create a session for EC2RoleProvider; prevents crash; fixes #3123

This commit is contained in:
Chris Bednarski 2016-02-19 17:10:05 -08:00
parent 344ed08f49
commit d0ab8658bc
1 changed files with 6 additions and 1 deletions

View File

@ -10,6 +10,8 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/credentials/ec2rolecreds"
"github.com/aws/aws-sdk-go/aws/ec2metadata"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/mitchellh/packer/template/interpolate"
)
@ -42,6 +44,7 @@ func (c *AccessConfig) Config() (*aws.Config, error) {
return nil, err
}
} else {
sess := session.New(config)
creds = credentials.NewChainCredentials([]credentials.Provider{
&credentials.StaticProvider{Value: credentials.Value{
AccessKeyID: c.AccessKey,
@ -50,7 +53,9 @@ func (c *AccessConfig) Config() (*aws.Config, error) {
}},
&credentials.EnvProvider{},
&credentials.SharedCredentialsProvider{Filename: "", Profile: ""},
&ec2rolecreds.EC2RoleProvider{},
&ec2rolecreds.EC2RoleProvider{
Client: ec2metadata.New(sess),
},
})
}
return config.WithCredentials(creds), nil