2021-10-17 17:15:44 +00:00
|
|
|
package train
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"github.com/aws/aws-sdk-go-v2/aws"
|
|
|
|
"github.com/aws/aws-sdk-go-v2/service/s3"
|
|
|
|
"github.com/aws/aws-sdk-go-v2/service/s3/types"
|
2021-11-24 18:10:52 +00:00
|
|
|
"github.com/cyrilix/robocar-tools/pkg/awsutils"
|
2021-11-24 18:32:24 +00:00
|
|
|
"go.uber.org/zap"
|
2021-10-17 17:15:44 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func ListArchives(ctx context.Context, bucket string) error {
|
2021-11-24 18:10:52 +00:00
|
|
|
client := s3.NewFromConfig(awsutils.MustLoadConfig())
|
2021-10-17 17:15:44 +00:00
|
|
|
|
|
|
|
prefix := aws.String("input/data/train/train.zip")
|
|
|
|
objects, err := client.ListObjectsV2(ctx, &s3.ListObjectsV2Input{
|
|
|
|
Bucket: aws.String(bucket),
|
|
|
|
Prefix: prefix,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("unable to list objects in bucket %v: %w", bucket, err)
|
|
|
|
}
|
|
|
|
fmt.Printf("objects: %v\n", objects)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t Training) UploadArchive(ctx context.Context, archive []byte) error {
|
|
|
|
client := s3.NewFromConfig(t.config)
|
|
|
|
key := aws.String("input/data/train/train.zip")
|
|
|
|
|
2021-11-24 18:32:24 +00:00
|
|
|
zap.S().Infof("upload archive to bucket '%s/%s'", t.bucketName, *key)
|
2021-10-17 17:15:44 +00:00
|
|
|
_, err := client.PutObject(
|
|
|
|
ctx,
|
|
|
|
&s3.PutObjectInput{
|
|
|
|
ACL: types.ObjectCannedACLPrivate,
|
|
|
|
Body: bytes.NewReader(archive),
|
|
|
|
Bucket: aws.String(t.bucketName),
|
|
|
|
Key: key,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("unable to upload archive: %w", err)
|
|
|
|
}
|
2021-11-24 18:32:24 +00:00
|
|
|
zap.S().Info("archive uploaded")
|
2021-10-17 17:15:44 +00:00
|
|
|
return nil
|
|
|
|
}
|