Guest User

Untitled

a guest
Feb 20th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4. "fmt"
  5. "log"
  6. "time"
  7.  
  8. "github.com/aws/aws-sdk-go/aws"
  9. "github.com/aws/aws-sdk-go/aws/session"
  10. "github.com/aws/aws-sdk-go/service/s3"
  11. "github.com/kelseyhightower/envconfig"
  12. )
  13.  
  14. func main() {
  15. configuration := s3.PutObjectInput{ Key: aws.String("default_key") }
  16.  
  17. // Add Bucket to configuration from environment variable
  18. // e.g:
  19. // CONFIGURATION_BUCKET -> configuration.Bucket
  20. err := envconfig.Process("configuration", &configuration)
  21.  
  22. if err != nil {
  23. log.Fatal(err.Error())
  24. }
  25.  
  26. sess := session.Must(session.NewSessionWithOptions(session.Options{
  27. SharedConfigState: session.SharedConfigEnable,
  28. }))
  29. svc := s3.New(sess)
  30. req, _ := svc.PutObjectRequest(&configuration)
  31.  
  32. url, err := req.Presign(15 * time.Minute)
  33.  
  34. if err != nil {
  35. log.Fatal(err.Error())
  36. }
  37. fmt.Println("Url is", url)
  38. }
  39.  
  40. fmt.Println(configuration.Bucket, configuration.Key) // returns address
Add Comment
Please, Sign In to add comment