我正在编写一个 go 函数来从 AWS S3 存储桶下载文件。
func DownloadFromS3Bucket() {
bucket := "cellery-runtime-installation"
item := "hello-world.txt"
file, err := os.Create(item)
if err != nil {
fmt.Println(err)
}
defer file.Close()
// Initialize a session in us-west-2 that the SDK will use to load
// credentials from the shared credentials file ~/.aws/credentials.
sess, _ := session.NewSession(&aws.Config{
Region: aws.String("us-east-1")},
)
downloader := s3manager.NewDownloader(sess)
numBytes, err := downloader.Download(file,
&s3.GetObjectInput{
Bucket: aws.String(bucket),
Key: aws.String(item),
})
if err != nil {
fmt.Println(err)
}
fmt.Println("Downloaded", file.Name(), numBytes, "bytes")
}
但是,我收到一条要求提供凭据的错误消息。
NoCredentialProviders:链中没有有效的提供者。已弃用。有关详细消息,请参阅 aws.Config.CredentialsChainVerboseErrors
该文档没有具体说明如何设置凭据。(访问密钥 ID,秘密访问密钥)
任何想法?