diff --git a/Golang/Aws-Upload-Multiple-Images/go.mod b/Golang/Aws-Upload-Multiple-Images/go.mod new file mode 100644 index 000000000..0af8b3356 --- /dev/null +++ b/Golang/Aws-Upload-Multiple-Images/go.mod @@ -0,0 +1,25 @@ +module main + +go 1.21.5 + +require ( + github.com/aws/aws-lambda-go v1.44.0 // indirect + github.com/aws/aws-sdk-go-v2 v1.24.1 // indirect + github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.5.4 // indirect + github.com/aws/aws-sdk-go-v2/config v1.26.3 // indirect + github.com/aws/aws-sdk-go-v2/credentials v1.16.14 // indirect + github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.14.11 // indirect + github.com/aws/aws-sdk-go-v2/internal/configsources v1.2.10 // indirect + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.5.10 // indirect + github.com/aws/aws-sdk-go-v2/internal/ini v1.7.2 // indirect + github.com/aws/aws-sdk-go-v2/internal/v4a v1.2.10 // indirect + github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.10.4 // indirect + github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.2.10 // indirect + github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.10.10 // indirect + github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.16.10 // indirect + github.com/aws/aws-sdk-go-v2/service/s3 v1.48.0 // indirect + github.com/aws/aws-sdk-go-v2/service/sso v1.18.6 // indirect + github.com/aws/aws-sdk-go-v2/service/ssooidc v1.21.6 // indirect + github.com/aws/aws-sdk-go-v2/service/sts v1.26.7 // indirect + github.com/aws/smithy-go v1.19.0 // indirect +) diff --git a/Golang/Aws-Upload-Multiple-Images/main.go b/Golang/Aws-Upload-Multiple-Images/main.go new file mode 100644 index 000000000..1884600f6 --- /dev/null +++ b/Golang/Aws-Upload-Multiple-Images/main.go @@ -0,0 +1,79 @@ +package main + +import ( + "context" + "fmt" + "io/ioutil" + "log" + "strings" + "sync" + + "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" +) + +func main() { + // Load the Shared AWS Configuration (~/.aws/config) + cfg, err := config.LoadDefaultConfig(context.TODO(), config.WithSharedConfigProfile("")) + //https://github.com/aws/aws-sdk-go-v2/blob/main/service/s3/api_op_GetBucketNotificationConfiguration.go + + if err != nil { + log.Fatal("coming from here") + log.Fatal(err) + } + + // Create an Amazon S3 service client + client := s3.NewFromConfig(cfg) + + fmt.Println("S3 event notification configured successfully.") + + type result struct { + Output *s3.PutObjectOutput + Err error + } + results := make(chan result, 2) + + var wg sync.WaitGroup + wg.Add(2) + go func() { + defer wg.Done() + content, err := ioutil.ReadFile("chad.jpeg") + if err != nil { + results <- result{Err: err} + return + } + output, err := client.PutObject(context.TODO(), &s3.PutObjectInput{ + Bucket: aws.String(""), + Key: aws.String("pfdffdcxdflus"), + Body: strings.NewReader(string(content)), + }) + results <- result{Output: output, Err: err} + }() + go func() { + defer wg.Done() + content, err := ioutil.ReadFile("giving a talk.jpg") + if err != nil { + results <- result{Err: err} + return + } + output, err := client.PutObject(context.TODO(), &s3.PutObjectInput{ + Bucket: aws.String(""), + Key: aws.String("minffdcxdfdus"), + Body: strings.NewReader(string(content)), + }) + results <- result{Output: output, Err: err} + }() + wg.Wait() + + close(results) + for result := range results { + if result.Err != nil { + log.Printf("error: %v", result.Err) + continue + } + fmt.Printf("etag: %v", aws.ToString(result.Output.ETag)) + } +} + +//https://aws.github.io/aws-sdk-go-v2/docs/getting-started/