func authFromEnvOrConfig(c Config) (aws.Auth, error) {
	auth, err := aws.EnvAuth()
	if err != nil {
		return aws.Auth{}, err
	}
	if c.AccessKey != "" {
		auth.AccessKey = c.AccessKey
	}
	if c.SecretKey != "" {
		auth.SecretKey = c.SecretKey
	}

	return auth, err
}
Esempio n. 2
0
func TestS3Upload(t *testing.T) {
	auth, err := aws.EnvAuth()

	s := s3.New(auth, aws.USEast)
	bucket := s.Bucket("downloaderd")

	data := []byte("Hello, Goamz!!")
	err = bucket.Put("sample.txt", data, "text/plain", s3.BucketOwnerFull)
	if err != nil {
		t.Errorf("upload-failed: %v", err)
	}

	err = bucket.Put("test/sample.txt", data, "text/plain", s3.BucketOwnerFull)
	if err != nil {
		t.Errorf("upload-failed: %v", err)
	}
}
Esempio n. 3
0
func main() {
	listen := flag.String("listen", "127.0.0.1:5000", "Address to listen to.")
	show_version := flag.Bool("version", false, "Print version and exit.")
	flag.Parse()

	var ok bool
	Region, ok = aws.Regions[AWSRegion]
	if !ok {
		log.Fatalf("Invalid AWS Region: %s", AWSRegion)
	}

	if *show_version {
		fmt.Println("elastic-nginx version", VERSION)
		return
	}

	var err error
	AWSAuth, err = aws.EnvAuth()
	if err != nil {
		log.Fatal(err)
	}

	Config, err = config.ReadFile(ConfigPath)
	if err != nil {
		log.Fatal(err)
	}

	http.HandleFunc("/", readMessage)

	log.Println("Listening on", *listen)
	log.Println("Monitoring events on topic:", Config.TopicArn)
	log.Println("AWS Region:", AWSRegion)
	for i, u := range Config.Upstreams {
		log.Printf("Upstream %d: %s", i, u.Name)
		log.Println("  ContainerFolder:", u.ContainerFolder)
		log.Println("  File:", u.File)
	}
	err = http.ListenAndServe(*listen, nil)
	if err != nil {
		log.Fatal(err)
	}
}
Esempio n. 4
0
func put() {

	// The AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables are used.
	auth, err := aws.EnvAuth()
	if err != nil {
		panic(err.Error())
	}

	// Open Bucket
	s := s3.New(auth, aws.USEast)
	bucket := s.Bucket("joburnet-lambda-sources")

	data := []byte("bang!")
	key := randSeq(32)

	err = bucket.Put(key, data, "content-type", s3.Private)
	if err != nil {
		fmt.Printf("%v", err)
	} else {
		fmt.Printf(".")
	}
}