Home > Article > Backend Development > How to Use AWS SDK v2 with Credentials from Variables?
Q: How do I run AWS SDK v2 with credentials from variables?
To leverage SDK v2 without using the legacy Session class, you can create a new client and pass your credentials as variables. Consider this getIAMClient function for the IAM service:
<code class="go">func getIAMClient(ctx context.Context) (*iam.Client, error) { cfg, err := config.LoadDefaultConfig(ctx, config.WithRegion("no-region")) if err != nil { return nil, errors.Wrap(err) } cfg.HTTPClient, err = getHTTPClient(ctx) if err != nil { return nil, err } // Use the StaticCredentialsProvider to pass credentials from variables. cfg.Credentials = credentials.NewStaticCredentialsProvider("AKID", "SECRET_KEY", "TOKEN") return iam.NewFromConfig(cfg), nil }</code>
This approach allows multiple users to utilize the application simultaneously without relying on environment variables.
The above is the detailed content of How to Use AWS SDK v2 with Credentials from Variables?. For more information, please follow other related articles on the PHP Chinese website!