Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
60 changes: 60 additions & 0 deletions aws/external/example_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package external_test

import (
"fmt"
"os"
"path/filepath"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/aws/external"
)

func ExampleWithSharedConfigProfile() {
cfg, err := external.LoadDefaultAWSConfig(
// Specify the shared configuration profile to load.
external.WithSharedConfigProfile("exampleProfile"),

// Optionally specify the specific shared configuraiton
// files to load the profile from.
external.WithSharedConfigFiles([]string{
filepath.Join("testdata", "shared_config"),
}),
)
if err != nil {
fmt.Fprintf(os.Stderr, "failed to load config, %v", err)
os.Exit(1)
}

// Region loaded from credentials file.
fmt.Println("Region:", cfg.Region)

// Output:
// Region: us-west-2
}

func ExampleWithCredentialsValue() {
cfg, err := external.LoadDefaultAWSConfig(
// Hard coded credentials.
external.WithCredentialsValue(aws.Credentials{
AccessKeyID: "AKID", SecretAccessKey: "SECRET", SessionToken: "SESSION",
Source: "example hard coded credentials",
}),
)
if err != nil {
fmt.Fprintf(os.Stderr, "failed to load config, %v", err)
os.Exit(1)
}

// Credentials retrieve will be called automatically internally to the SDK
// service clients created with the cfg value.
creds, err := cfg.Credentials.Retrieve()
if err != nil {
fmt.Fprintf(os.Stderr, "failed to get credentials, %v", err)
os.Exit(1)
}

fmt.Println("Credentials Source:", creds.Source)

// Output:
// Credentials Source: example hard coded credentials
}
5 changes: 5 additions & 0 deletions aws/external/testdata/shared_config
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ s3 =

region = default_region

[profile exampleProfile]
region = us-west-2
aws_access_key_id = AKID
aws_secret_access_key = SECRET

[profile alt_profile_name]
region = alt_profile_name_region

Expand Down