Go to file
Rohan Verma ad0419ef77
Merge pull request #18 from rhnvrm/feat-file-put
feat: add support for FilePut
2021-12-29 15:02:42 +05:30
.github/workflows chore: remove debug flag in aws command 2021-02-09 19:19:49 +05:30
testdata refactor: move avatar to testdata folder 2019-12-11 15:32:55 +05:30
.gitignore Add Endpoint for some compatible instance and fix time format (#3) 2019-12-11 07:53:05 +00:00
LICENSE init 2018-12-06 15:54:47 +05:30
README.md docs: Make bucket references in README example consistent 2021-02-03 17:47:51 +02:00
go.mod refactor: minor doc changes 2019-12-11 13:54:46 +05:30
go.sum init 2018-12-06 15:54:47 +05:30
policy.go feat: add support for FilePut 2021-12-29 13:59:45 +05:30
presigned.go Fix: Add X-Amz-Security-Token to presigned url (#4) 2020-04-13 16:44:33 +05:30
presigned_test.go Fix: Add X-Amz-Security-Token to presigned url (#4) 2020-04-13 16:44:33 +05:30
sign.go fix: minor doc changes 2021-07-19 12:33:48 +05:30
simples3.go feat: add support for FilePut 2021-12-29 13:59:45 +05:30
simples3_test.go feat: add support for FilePut 2021-12-29 13:59:45 +05:30

README.md

simples3 : Simple no frills AWS S3 Library using REST with V4 Signing

Overview GoDoc Go Report Card GoCover Zerodha Tech

SimpleS3 is a golang library for uploading and deleting objects on S3 buckets using REST API calls or Presigned URLs signed using AWS Signature Version 4.

Install

go get github.com/rhnvrm/simples3

Example

testTxt, _ := os.Open("testdata/test.txt")
defer testTxt.Close()

// Create an instance of the package
// You can either create by manually supplying credentials
// (preferably using Environment vars)
s3 := simples3.New(Region, AWSAccessKey, AWSSecretKey)
// or you can use this on an EC2 instance to 
// obtain credentials from IAM attached to the instance.
s3, _ := simples3.NewUsingIAM(Region)

// You can also set a custom endpoint to a compatible s3 instance. 
s3.SetEndpoint(CustomEndpoint)

// Note: Consider adding a testTxt.Seek(0, 0)
// in case you have read 
// the body, as the pointer is shared by the library.

// File Upload is as simple as providing the following
// details.
resp, err := s3.FileUpload(simples3.UploadInput{
    Bucket:      AWSBucket,
    ObjectKey:   "test.txt",
    ContentType: "text/plain",
    FileName:    "test.txt",
    Body:        testTxt,
})

// Similarly, Files can be deleted.
err := s3.FileDelete(simples3.DeleteInput{
    Bucket:    os.Getenv("AWS_S3_BUCKET"),
    ObjectKey: "test.txt",
})

// You can also download the file.
file, _ := s3.FileDownload(simples3.DownloadInput{
    Bucket:    AWSBucket,
    ObjectKey: "test.txt",
})
data, _ := ioutil.ReadAll(file)
file.Close()

// You can also use this library to generate
// Presigned URLs that can for eg. be used to
// GET/PUT files on S3 through the browser.
var time, _ = time.Parse(time.RFC1123, "Fri, 24 May 2013 00:00:00 GMT")

url := s.GeneratePresignedURL(PresignedInput{
    Bucket:        AWSBucket,
    ObjectKey:     "test.txt",
    Method:        "GET",
    Timestamp:     time,
    ExpirySeconds: 86400,
})

Contributing

You are more than welcome to contribute to this project. Fork and make a Pull Request, or create an Issue if you see any problem or want to propose a feature.

Author

Rohan Verma hello@rohanverma.net

License

BSD-2-Clause-FreeBSD