Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added aws script-golang for uploading multiple files together using g… #1441

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions Golang/Aws-Upload-Multiple-Images/go.mod
Original file line number Diff line number Diff line change
@@ -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
)
79 changes: 79 additions & 0 deletions Golang/Aws-Upload-Multiple-Images/main.go
Original file line number Diff line number Diff line change
@@ -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("<Your-Profile-name>"))
//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("<Your-bucket-name>"),
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("<Your-bucket-name>"),
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/
Loading