Last active
August 29, 2015 14:11
-
-
Save pwaller/10231b176626a3b86948 to your computer and use it in GitHub Desktop.
s4cat (simple s3 cat)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Note: doesn't work yet. | |
// Note: you may wish to modify the hard-coded region from eu-west-1. | |
package main | |
import ( | |
"io" | |
"log" | |
"os" | |
"github.com/stripe/aws-go/aws" | |
"github.com/stripe/aws-go/gen/s3" | |
) | |
func main() { | |
if len(os.Args) < 3 { | |
log.Fatal("usage: s4cat <bucket> <key>") | |
} | |
bucket, key := os.Args[1], os.Args[2] | |
creds := aws.InstanceRoleCredentials() | |
s := s3.New(creds, "eu-west-1", nil) | |
resp, err := s.GetObject(&s3.GetObjectRequest{ | |
Bucket: aws.String(bucket), | |
Key: aws.String(key), | |
}) | |
if err != nil { | |
log.Fatalf("GetObject Failed: %#+v", err) | |
} | |
n, err := io.Copy(os.Stdout, resp.Body) | |
if err != nil { | |
log.Fatal("Copy failed:", err) | |
} | |
log.Println("Copied", n, "bytes") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment