Created
January 2, 2024 08:52
-
-
Save anboo/036b8579811afb75b14cc9999602edf8 to your computer and use it in GitHub Desktop.
Yandex cloud S3 storage example connect from golang aws S3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
customResolver := aws.EndpointResolverWithOptionsFunc(func(service, region string, options ...interface{}) (aws.Endpoint, error) { | |
if service == s3.ServiceID { | |
return aws.Endpoint{ | |
PartitionID: "yc", | |
URL: "https://storage.yandexcloud.net", | |
}, nil | |
} | |
return aws.Endpoint{}, fmt.Errorf("unknown endpoint requested") | |
}) | |
cfg, err := config.LoadDefaultConfig( | |
context.Background(), | |
config.WithEndpointResolverWithOptions(customResolver), | |
config.WithCredentialsProvider( | |
&credentials.StaticCredentialsProvider{ | |
Value: aws.Credentials{ | |
AccessKeyID: conf.YandexKeyID, | |
SecretAccessKey: conf.YandexKeySecret, | |
}, | |
}, | |
), | |
config.WithRegion("auto"), | |
) | |
client := s3.NewFromConfig(cfg) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment