added bundle generation
This commit is contained in:
parent
ca06a91dc6
commit
f89883e745
8 changed files with 536 additions and 0 deletions
46
pipeline/05_bundle_gen/s3.go
Normal file
46
pipeline/05_bundle_gen/s3.go
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"io"
|
||||
|
||||
"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"
|
||||
)
|
||||
|
||||
var s3Client *s3.Client
|
||||
|
||||
func initS3() error {
|
||||
cfg, err := config.LoadDefaultConfig(context.Background(), config.WithRegion("us-east-1"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
s3Client = s3.NewFromConfig(cfg)
|
||||
return nil
|
||||
}
|
||||
|
||||
// s3Download fetches an object from S3.
|
||||
func s3Download(ctx context.Context, bucket, key string) ([]byte, error) {
|
||||
resp, err := s3Client.GetObject(ctx, &s3.GetObjectInput{
|
||||
Bucket: aws.String(bucket),
|
||||
Key: aws.String(key),
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
return io.ReadAll(resp.Body)
|
||||
}
|
||||
|
||||
// s3UploadBundle uploads a bundle JSON to S3.
|
||||
func s3UploadBundle(ctx context.Context, bucket, key string, data []byte) error {
|
||||
_, err := s3Client.PutObject(ctx, &s3.PutObjectInput{
|
||||
Bucket: aws.String(bucket),
|
||||
Key: aws.String(key),
|
||||
Body: bytes.NewReader(data),
|
||||
ContentType: aws.String("application/json"),
|
||||
})
|
||||
return err
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue