# Changes related to golang-github-aws-aws-sdk-go latest upload
# Patch by Filippo Giunchedi <filippo@debian.org>

# Added by Martín Ferrari: revert most of commit bec6870, as that change
# requires version 1.5 of the SDK.

--- a/config/config.go
+++ b/config/config.go
@@ -1114,7 +1114,6 @@
 	Region          string         `yaml:"region"`
 	AccessKey       string         `yaml:"access_key,omitempty"`
 	SecretKey       Secret         `yaml:"secret_key,omitempty"`
-	Profile         string         `yaml:"profile,omitempty"`
 	RefreshInterval model.Duration `yaml:"refresh_interval,omitempty"`
 	Port            int            `yaml:"port"`
 
--- a/config/config_test.go
+++ b/config/config_test.go
@@ -376,7 +376,6 @@
 						Region:          "us-east-1",
 						AccessKey:       "access",
 						SecretKey:       "mysecret",
-						Profile:         "profile",
 						RefreshInterval: model.Duration(60 * time.Second),
 						Port:            80,
 					},
--- a/config/testdata/conf.good.yml
+++ b/config/testdata/conf.good.yml
@@ -170,7 +170,6 @@
     - region: us-east-1
       access_key: access
       secret_key: mysecret
-      profile: profile
 
 - job_name: service-azure
   azure_sd_configs:
--- a/discovery/ec2/ec2.go
+++ b/discovery/ec2/ec2.go
@@ -70,7 +70,6 @@
 type Discovery struct {
 	aws      *aws.Config
 	interval time.Duration
-	profile  string
 	port     int
 	logger   log.Logger
 }
@@ -79,14 +78,13 @@
 func NewDiscovery(conf *config.EC2SDConfig, logger log.Logger) *Discovery {
 	creds := credentials.NewStaticCredentials(conf.AccessKey, string(conf.SecretKey), "")
 	if conf.AccessKey == "" && conf.SecretKey == "" {
-		creds = nil
+		creds = credentials.NewEnvCredentials()
 	}
 	return &Discovery{
 		aws: &aws.Config{
 			Region:      &conf.Region,
 			Credentials: creds,
 		},
-		profile:  conf.Profile,
 		interval: time.Duration(conf.RefreshInterval),
 		port:     conf.Port,
 		logger:   logger,
@@ -139,15 +137,7 @@
 		}
 	}()
 
-	sess, err := session.NewSessionWithOptions(session.Options{
-		Config:  *d.aws,
-		Profile: d.profile,
-	})
-	if err != nil {
-		return nil, fmt.Errorf("could not create aws session: %s", err)
-	}
-
-	ec2s := ec2.New(sess)
+	ec2s := ec2.New(session.New(), d.aws)
 	tg = &config.TargetGroup{
 		Source: *d.aws.Region,
 	}
