diff --git a/core/utils/diskfree_nonwindows.go b/core/utils/diskfree_nonwindows.go index 4697b081..266c8e5d 100644 --- a/core/utils/diskfree_nonwindows.go +++ b/core/utils/diskfree_nonwindows.go @@ -3,7 +3,6 @@ package utils import ( - "fmt" "os" "golang.org/x/sys/unix" @@ -21,6 +20,18 @@ func GetDiskAvailableBytes() (uint64, error) { return 0, err } + /* An example of output on Lambda: + Bavail: 393433 + Bfree: 397529 + Blocks: 397532 + Bsize: 4096 + Ffree: 434325 + Files: 434336 + Flags: 4128 + Fsid: [-1480289054 1771191333] + Type: 61267 + Disk free space: 1611501568 + fmt.Printf("Bavail: %v\n", stat.Bavail) fmt.Printf("Bfree: %v\n", stat.Bfree) fmt.Printf("Blocks: %v\n", stat.Blocks) @@ -37,7 +48,7 @@ func GetDiskAvailableBytes() (uint64, error) { //fmt.Printf("Mntonname: %v\n", stat.Mntonname) //fmt.Printf("Owner: %v\n", stat.Owner) fmt.Printf("Type: %v\n", stat.Type) - + */ // Available blocks * size per block = available space in bytes return stat.Bavail * uint64(stat.Bsize), nil } diff --git a/internal/lambdas/data-import/main.go b/internal/lambdas/data-import/main.go index 330ddd5c..bbd25d4f 100644 --- a/internal/lambdas/data-import/main.go +++ b/internal/lambdas/data-import/main.go @@ -81,16 +81,28 @@ func HandleRequest(ctx context.Context, event awsutil.Event) (string, error) { // and it'll be useful for initial debugging fmt.Printf("ImportForTrigger: \"%v\"\n", record.SNS.Message) - err = os.Chdir(os.TempDir()) + wd, err := os.Getwd() if err != nil { - fmt.Printf("Failed to change to temp dir: %v\n", err) - } - - freeBytes, err := utils.GetDiskAvailableBytes() - if err != nil { - fmt.Printf("Failed to read disk free space: %v\n", err) + fmt.Printf("Failed to get working dir: %v\n", err) } else { - fmt.Printf("Disk free space: %v\n", freeBytes) + fmt.Printf("Working dir: %v\n", wd) + + err = os.Chdir(os.TempDir()) + if err != nil { + fmt.Printf("Failed to change to temp dir: %v\n", err) + } + + freeBytes, err := utils.GetDiskAvailableBytes() + if err != nil { + fmt.Printf("Failed to read disk free space: %v\n", err) + } else { + fmt.Printf("Disk free space: %v\n", freeBytes) + } + + err = os.Chdir(wd) + if err != nil { + fmt.Printf("Failed to change to working dir: %v\n", err) + } } mongoClient, _, err := mongoDBConnection.Connect(sess, mongoSecret, iLog)