Home > Backend Development > Golang > How to Set AWS Credentials from Variables Using SDK V2 in Go?

How to Set AWS Credentials from Variables Using SDK V2 in Go?

Susan Sarandon
Release: 2024-11-01 08:26:30
Original
931 people have browsed it

How to Set AWS Credentials from Variables Using SDK V2 in Go?

AWS SDK V2: Setting Credentials from Variables

This article resolves the query of how to use credentials from variables when working with AWS SDK version 2 for Go.

Question:

A developer seeks to create a new client and use the IAM service with credentials stored as variables. However, the SDK v2 no longer uses the Session approach, unlike the previous version, leaving them uncertain about how to pass these credentials effectively.

Solution:

To address this, the StaticCredentialsProvider can be utilized, as outlined in the AWS SDK for Go V2 documentation's "Static Credentials" section:

<code class="go">cfg, err := config.LoadDefaultConfig(ctx, config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider("AKID", "SECRET_KEY", "TOKEN")))
if err != nil {
    // Handle error
}</code>
Copy after login

In this example, the AKID, SECRET_KEY, and TOKEN values represent the credentials to be used by the client. This approach allows multiple users to access the application concurrently without resorting to ENV files.

The above is the detailed content of How to Set AWS Credentials from Variables Using SDK V2 in Go?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template