6 "github.com/aws/aws-sdk-go/aws/awserr"
9 // EnvProviderName provides a name of Env provider
10 const EnvProviderName = "EnvProvider"
13 // ErrAccessKeyIDNotFound is returned when the AWS Access Key ID can't be
14 // found in the process's environment.
15 ErrAccessKeyIDNotFound = awserr.New("EnvAccessKeyNotFound", "AWS_ACCESS_KEY_ID or AWS_ACCESS_KEY not found in environment", nil)
17 // ErrSecretAccessKeyNotFound is returned when the AWS Secret Access Key
18 // can't be found in the process's environment.
19 ErrSecretAccessKeyNotFound = awserr.New("EnvSecretNotFound", "AWS_SECRET_ACCESS_KEY or AWS_SECRET_KEY not found in environment", nil)
22 // A EnvProvider retrieves credentials from the environment variables of the
23 // running process. Environment credentials never expire.
25 // Environment variables used:
27 // * Access Key ID: AWS_ACCESS_KEY_ID or AWS_ACCESS_KEY
29 // * Secret Access Key: AWS_SECRET_ACCESS_KEY or AWS_SECRET_KEY
30 type EnvProvider struct {
34 // NewEnvCredentials returns a pointer to a new Credentials object
35 // wrapping the environment variable provider.
36 func NewEnvCredentials() *Credentials {
37 return NewCredentials(&EnvProvider{})
40 // Retrieve retrieves the keys from the environment.
41 func (e *EnvProvider) Retrieve() (Value, error) {
44 id := os.Getenv("AWS_ACCESS_KEY_ID")
46 id = os.Getenv("AWS_ACCESS_KEY")
49 secret := os.Getenv("AWS_SECRET_ACCESS_KEY")
51 secret = os.Getenv("AWS_SECRET_KEY")
55 return Value{ProviderName: EnvProviderName}, ErrAccessKeyIDNotFound
59 return Value{ProviderName: EnvProviderName}, ErrSecretAccessKeyNotFound
65 SecretAccessKey: secret,
66 SessionToken: os.Getenv("AWS_SESSION_TOKEN"),
67 ProviderName: EnvProviderName,
71 // IsExpired returns if the credentials have been retrieved.
72 func (e *EnvProvider) IsExpired() bool {