-1

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?

ayb jax
  • 121
  • 1
  • 7

1 Answers1

1

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)
Peter
  • 29,454
  • 5
  • 48
  • 60