Created
February 16, 2018 15:53
-
-
Save lkrych/b49ac11aef79edaa24794fc1e3cfe323 to your computer and use it in GitHub Desktop.
use bucket and prefix to specify search path in s3
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
package main | |
import ( | |
"fmt" | |
"log" | |
"os" | |
"strings" | |
"github.com/aws/aws-sdk-go/aws" | |
"github.com/aws/aws-sdk-go/aws/credentials" | |
"github.com/aws/aws-sdk-go/aws/session" | |
"github.com/aws/aws-sdk-go/service/s3" | |
) | |
//don't hardcode your credentials, I am just including them here for completeness | |
//see https://docs.aws.amazon.com/sdk-for-go/v1/developer-guide/setting-up.html for more info on how to do this correctly | |
const awsAccessKeyID = "keykey" | |
const awsSecretAccessKey = "secretsecret" | |
func main() { | |
//establish a session... | |
//essential for establishing a search path | |
bucket := "mybucket" | |
prefix := "super/specific/path" | |
//used to enumerate how many items you've searched through | |
itemCount := 0 | |
jsonCount := 0 | |
pageNum := 0 | |
//use the bucket and prefix to localize the search in s3 | |
s3InputParams := &s3.ListObjectsInput{Bucket: aws.String(bucket), Prefix: aws.String(prefix)} | |
//iterate through our objects | |
fmt.Println("") | |
fmt.Println("Found", jsonCount, "info.json files in bucket", bucket, "out of", itemCount, "items", "and", pageNum, "pages") | |
fmt.Println("") | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment