Hôm nay nghịch tý golang call vào aws
ở V2 còn nhiều compose chưa được phát triển
bài này mình test với S3 trên aws.
api error PermanentRedirect: The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.
Resolve:
Và sau đây là code sample
package main import ( "context" "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/config" "github.com/aws/aws-sdk-go-v2/service/s3" "log" "os" ) func main() { // Set Environment Variables os.Setenv("AWS_ACCESS_KEY_ID", "AKIATU2QSHIIZQXXXX") os.Setenv("AWS_SECRET_ACCESS_KEY", "ctR4JSP1rQR7JuTYDd9zLTqlXXXXXXXXiL+5s") // Load the Shared AWS Configuration (~/.aws/config) cfg, err := config.LoadDefaultConfig(context.TODO(), config.WithRegion("us-east-1")) if err != nil { log.Fatal(err) } // Create an Amazon S3 service client client := s3.NewFromConfig(cfg) // Get the first page of results for ListObjectsV2 for a bucket output, err := client.ListObjectsV2(context.TODO(), &s3.ListObjectsV2Input{ Bucket: aws.String("backend-terraform-250887682577"), }) if err != nil { log.Fatal(err) } log.Println("first page results:") for _, object := range output.Contents { log.Printf("key=%s size=%d", aws.ToString(object.Key), object.Size) } }