Skip to content

Instantly share code, notes, and snippets.

@munisystem
Last active September 3, 2017 11:29
Show Gist options
  • Save munisystem/dc04a93f7a7b40a986b7b87c792a2d38 to your computer and use it in GitHub Desktop.
Save munisystem/dc04a93f7a7b40a986b7b87c792a2d38 to your computer and use it in GitHub Desktop.
package s3
import (
"bytes"
"fmt"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"
)
type S3 struct {
Service *s3.S3
}
func NewClient() *S3 {
return &S3{
Service: s3.New(session.Must(session.NewSession())),
}
}
func (s *S3) Put(bucket, key string, body []byte) error {
input := &s3.PutObjectInput{
Bucket: aws.String(bucket),
Key: aws.String(key),
Body: bytes.NewReader(body),
}
if _, err := s.Service.PutObject(input); err != nil {
return fmt.Errorf("Faild to add object to S3 (bucket: %s, key: %s): %s", bucket, key, err.Error())
}
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment