英文:
s3 golang: Credentials provided as string
问题
你好!
在我的项目中,我需要上传和下载到不同的存储桶以检索和上传文件。凭据是由数据库提供的。
然而,golang aws sdk(v2)似乎不支持在运行时使用访问密钥和访问ID。它似乎要求凭据存储在主目录的.aws目录中。
有没有可能的解决方案?
英文:
Good day!
In my project, I need to upload and download to various buckets to retrieve and upload files. Credentials are provided by database.
However, golang aws sdk (v2) seems not support access key and access id during runtime. It seems to require credentials to be stored in home .aws directory.
Is there any possible solutions for that?
答案1
得分: 1
credentials package提供了多种来源,包括直接将密钥作为字符串传递:
import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"
)
awsSession, err := session.NewSessionWithOptions(session.Options{
// ...
Config: aws.Config{
// ...
Credentials: credentials.NewStaticCredentials(
"my-access-key",
"my-secret-key",
"",
),
},
})
if err != nil {
// ...
}
s3Client := s3.New(awsSession)
英文:
The credentials package offers a variety of sources, including passing keys as strings directly:
import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"
)
awsSession, err := session.NewSessionWithOptions(session.Options{
// ...
Config: aws.Config{
// ...
Credentials: credentials.NewStaticCredentials(
"my-access-key",
"my-secret-key",
"",
),
},
})
if err != nil {
// ...
}
s3Client := s3.New(awsSession)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论