MyDocs

# aws-sdk-go-v2でprofileを使う

profile を指定している場合は profile を使うが、指定していない場合は IAM ロールを使う。

func session(ctx context.Context, profile string) (aws.Config, error) {
	configOptions := []func(*config.LoadOptions) error{
		config.WithRegion("ap-northeast-1"),
	}
	if profile != "" {
		configOptions = append(configOptions, config.WithSharedConfigProfile(aws.ToString(&profile)))
	}
	cfg, err := config.LoadDefaultConfig(ctx, configOptions...)
	if err != nil {
		return aws.Config{}, err
	}
	return cfg, nil
}

このコード が参考になった。