title: open no such file or directory
body: <p>I am trying to follow AWS lambda go and s3 examples to create a function which will download the file from s3 resize it and upload back to s3. </p>
  
  <p>When I build the function and run it on local machine, everything works fine, when I run it as lambda I get ""open /tmp/images/users/original/5bba5c0f01e2f_dcadcc7139454bf6dba4cbd01a7c92f8.jpeg: no such file or directory"</p>
  
  <p>Here is my code</p>
  
  <pre><code>package main
  
  import (
      "github.com/aws/aws-sdk-go/aws"
      "github.com/aws/aws-sdk-go/aws/session"
      "github.com/aws/aws-sdk-go/service/s3"
      "github.com/aws/aws-sdk-go/service/s3/s3manager"
      "github.com/aws/aws-lambda-go/lambda"
      "github.com/nfnt/resize"
      "image/jpeg"
  
      "fmt"
      "os"
  )
  
  
  func HandleRequest() (string, error) {
       return runResize("5bba5c0f01e2f_dcadcc7139454bf6dba4cbd01a7c92f8.jpeg"), nil
  }
  
  func main() {
          lambda.Start(HandleRequest)
  }
  
  func runResize(item_name string) {
      bucket := "bucket"
      folder_name := "images/users/original/"
      folder_name_220x220 := "images/users/220x220/"
      folder_name_250x250 := "images/users/250x250/"
      folder_name_500x500 := "images/users/500x500/"
      folder_name_large := "images/users/large/"
  
      createFolder(folder_name)
      createFolder(folder_name_220x220)
      createFolder(folder_name_250x250)
      createFolder(folder_name_500x500)
      createFolder(folder_name_large)
  
      item := folder_name + item_name
  
      fmt.Printf("Creating file %q \n", item)
  
  
      file, err :=  os.Create(item)
      if err != nil {
          exitErrorf("Unable to open file %q", err)
      }
  
      defer file.Close()
  
      sess, _ := session.NewSession(&amp;aws.Config{
          Region: aws.String("us-east-1")},
      )
  
      downloader := s3manager.NewDownloader(sess)
  
      numBytes, err := downloader.Download(file,
          &amp;s3.GetObjectInput{
              Bucket: aws.String(bucket),
              Key:    aws.String(item),
          })
      if err != nil {
          exitErrorf("Unable to download item %q, %v", item, err)
      }
  
  
      if err != nil {
          exitErrorf("Unable to download item %q, %v", item, err)
      }
  
      // decode jpeg into image.Image
      img, err := jpeg.Decode(file)
      if err != nil {
          exitErrorf("Unable to download item %q, %v", item, err)
      }
      file.Close()
  
  
      m := resize.Thumbnail(1500, 1500, img, resize.Lanczos3)
      out, err := os.OpenFile(folder_name_large + item_name, os.O_RDWR|os.O_CREATE, 0666)
      if err != nil {
          exitErrorf("Unable to resize item %q, %v", item, err)
      }
      defer out.Close()
      jpeg.Encode(out, m, nil)
  
  
      m = resize.Thumbnail(500, 500, img, resize.Lanczos3)
      out, err = os.OpenFile(folder_name_500x500 + item_name, os.O_RDWR|os.O_CREATE, 0666)
      if err != nil {
          exitErrorf("Unable to resize item %q, %v", item, err)
      }
      defer out.Close()
      jpeg.Encode(out, m, nil)
  
      m = resize.Thumbnail(250, 250, img, resize.Lanczos3)
      out, err = os.OpenFile(folder_name_250x250 + item_name, os.O_RDWR|os.O_CREATE, 0666)
      if err != nil {
          exitErrorf("Unable to resize item %q, %v", item, err)
      }
      defer out.Close()
      jpeg.Encode(out, m, nil)
  
      m = resize.Thumbnail(220, 220, img, resize.Lanczos3)
      out, err =  os.OpenFile(folder_name_220x220 + item_name, os.O_RDWR|os.O_CREATE, 0666)
      if err != nil {
          exitErrorf("Unable to resize item %q, %v", item, err)
      }
      defer out.Close()
      jpeg.Encode(out, m, nil)
  
      uploadFile(folder_name_220x220 + item_name, bucket)
      uploadFile(folder_name_250x250 + item_name, bucket)
      uploadFile(folder_name_500x500 + item_name, bucket)
      uploadFile(folder_name_large + item_name, bucket)
  
  
      fmt.Println("Processed", file.Name(), numBytes, "bytes")
  }
  
  func createFolder(folder_name string) {
      if _, err := os.Stat(folder_name); os.IsNotExist(err) {
          os.MkdirAll(folder_name, os.ModePerm)
          fmt.Printf("Folder created %q \n", folder_name)
      }
  }
  
  func uploadFile(filename string, bucket string){
      file, err := os.Open(filename)
      if err != nil {
          exitErrorf("Unable to open file %q, %v", err)
      }
  
      defer file.Close()
      sess, err := session.NewSession(&amp;aws.Config{
          Region: aws.String("us-east-1")},
      )
  
      uploader := s3manager.NewUploader(sess)
      _, err = uploader.Upload(&amp;s3manager.UploadInput{
          Bucket: aws.String(bucket),
          Key: aws.String(filename),
          Body: file,
          ACL:  aws.String("public-read"),
      })
      if err != nil {
          // Print the error and exit.
          exitErrorf("Unable to upload %q to %q, %v", filename, bucket, err)
      }
  
  fmt.Printf("Successfully uploaded %q to %q\n", filename, bucket)
  }
  
  
  func exitErrorf(msg string, args ...interface{}) {
      fmt.Fprintf(os.Stderr, msg+"\n", args...)
      os.Exit(1)
  }
  </code></pre>
  
  <p>Here is how I build </p>
  
  <pre><code>GOOS=linux go build -v -ldflags '-d -s -w' -a -tags netgo -installsuffix netgo -o resize &amp;&amp; zip deployment.zip resize
  </code></pre>
  
  <p>When I run locally, it all works fine, but when running on lambda get, I get the error </p>