Go

    1. import (
    2. "context"
    3. "log"
    4. "github.com/aws/aws-sdk-go-v2/aws"
    5. "github.com/aws/aws-sdk-go-v2/config"
    6. "github.com/aws/aws-sdk-go-v2/service/s3"
    7. )
    8. func main() {
    9. awsEndpoint = "http://localhost:4566"
    10. awsRegion = "us-east-1"
    11. customResolver := aws.EndpointResolverFunc(func(service, region string) (aws.Endpoint, error) {
    12. if awsEndpoint != "" {
    13. return aws.Endpoint{
    14. PartitionID: "aws",
    15. URL: awsEndpoint,
    16. SigningRegion: awsRegion,
    17. }, nil
    18. }
    19. // returning EndpointNotFoundError will allow the service to fallback to its default resolution
    20. return aws.Endpoint{}, &aws.EndpointNotFoundError{}
    21. })
    22. config.WithRegion(awsRegion),
    23. config.WithEndpointResolver(customResolver),
    24. )
    25. if err != nil {
    26. log.Fatalf("Cannot load the AWS configs: %s", err)
    27. }
    28. // Create the resource client
    29. client = s3.NewFromConfig(awsCfg, func(o *s3.Options) {
    30. o.UsePathStyle = true
    31. })
    32. // ...
    33. }