I'm pretty sure that the only writeable file system on Lambda in under
/tmp. You're not checking the error return from os.MkdirAll, but that call
is probably failing before you get to os.Create. Also keep in mind that
each Lambda instance is limited to 512 MB of /tmp space:
https://docs.aws.amazon.com/lambda/latest/dg/limits.html

Jim

On Tue, Oct 16, 2018 at 3:46 PM AE <elbaky...@gmail.com> wrote:

> Hello,
>
> I am trying to make function which will down file fro aws s3 and do some
> image resizing. I am having issue with os.Create, when I run locally on ec2
> machine it works fine but when I run on lambda directly I get error file
> not found
>
>
> 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"
>
> )
> type MyEvent struct {
>         Name string `json:"name"`
> }
>
> func HandleRequest() (string, error) {
>             runResize(
> "5bba5c0f01e2f_dcadcc7139454bf6dba4cbd01a7c92f8.jpeg")
>         return fmt.Sprintf("Hello"), nil
> }
>
> func main() {
>  //       lambda.Start(HandleRequest)
> runResize("5bba5c0f01e2f_dcadcc7139454bf6dba4cbd01a7c92f8.jpeg")
>
> }
>
> 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(&aws.Config{
>         Region: aws.String("us-east-1")},
>     )
>     downloader := s3manager.NewDownloader(sess)
>     numBytes, err := downloader.Download(file,
>         &s3.GetObjectInput{
>             Bucket: aws.String(bucket),
>             Key:    aws.String(item),
>         })
>
>     if err != nil {
>
>         exitErrorf("Unable to download item %q, %v", item, err)
>
>     }
>    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 exitErrorf(msg string, args ...interface{}) {
>
>     fmt.Fprintf(os.Stderr, msg+"\n", args...)
>
>     os.Exit(1)
>
> }
>
>
>
> Here how I build the code for deployment
>
>
> GOOS=linux go build -v -ldflags '-d -s -w' -a -tags netgo -installsuffix
> netgo -o resize && zip deployment.zip resize
>
>
> and error I am getting
>
>
> Unable to open file "open
> images/users/original/5bba5c0f01e2f_dcadcc7139454bf6dba4cbd01a7c92f8.jpeg:
> no such file or directory"
>
> This error i thrown on create on in LAMBDA
>
>
>
> Thanks
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to