1package config_test
2
3import (
4	"context"
5	"fmt"
6	"log"
7
8	"github.com/aws/aws-sdk-go-v2/aws"
9	"github.com/aws/aws-sdk-go-v2/config"
10	"github.com/aws/aws-sdk-go-v2/service/sts"
11)
12
13func Example() {
14	ctx := context.TODO()
15	cfg, err := config.LoadDefaultConfig(ctx)
16	if err != nil {
17		log.Fatal(err)
18	}
19
20	client := sts.NewFromConfig(cfg)
21	identity, err := client.GetCallerIdentity(ctx, &sts.GetCallerIdentityInput{})
22	if err != nil {
23		log.Fatal(err)
24	}
25
26	fmt.Printf("Account: %s, Arn: %s", aws.ToString(identity.Account), aws.ToString(identity.Arn))
27}
28
29func Example_custom_config() {
30	ctx := context.TODO()
31
32	// Config sources can be passed to LoadDefaultConfig, these sources can implement one or more
33	// provider interfaces. These sources take priority over the standard environment and shared configuration values.
34	cfg, err := config.LoadDefaultConfig(ctx,
35		config.WithRegion("us-west-2"),
36		config.WithSharedConfigProfile("customProfile"),
37	)
38	if err != nil {
39		log.Fatal(err)
40	}
41
42	client := sts.NewFromConfig(cfg)
43	identity, err := client.GetCallerIdentity(ctx, &sts.GetCallerIdentityInput{})
44	if err != nil {
45		log.Fatal(err)
46	}
47
48	fmt.Printf("Account: %s, Arn: %s", aws.ToString(identity.Account), aws.ToString(identity.Arn))
49}
50