accept aws credentials from environment variables

This commit is contained in:
nyanotech 2024-04-08 21:39:53 -07:00
parent 11b3be2f16
commit fbf4229e96
Signed by: nyanotech
GPG Key ID: D2D0A9E8F160472B

16
main.go
View File

@ -30,9 +30,10 @@ var threadCount = flag.Int("threads", 1024, "how many objects to operate on at a
func main() { func main() {
flag.Parse() flag.Parse()
cfg, err := config.LoadDefaultConfig(context.TODO(), options := []func(*config.LoadOptions) error{}
// just a placeholder because it needs to be defined
// should be using the one from the endpoint regardless options = append(options,
// TODO: figure out what to do with this
config.WithRegion("us-east-1"), config.WithRegion("us-east-1"),
config.WithEndpointResolverWithOptions(aws.EndpointResolverWithOptionsFunc( config.WithEndpointResolverWithOptions(aws.EndpointResolverWithOptionsFunc(
func(service, region string, options ...interface{}) (aws.Endpoint, error) { func(service, region string, options ...interface{}) (aws.Endpoint, error) {
@ -41,7 +42,14 @@ func main() {
}, nil }, nil
}, },
)), )),
config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider(*accessKeyId, *secretAccessKey, "")), )
if *accessKeyId != "" && *secretAccessKey != "" {
options = append(options, config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider(*accessKeyId, *secretAccessKey, "")))
}
cfg, err := config.LoadDefaultConfig(context.TODO(),
options...,
) )
if err != nil { if err != nil {
log.Fatalln("Failed to create AWS config", err) log.Fatalln("Failed to create AWS config", err)