user3259472
user3259472

Reputation:

Python/AWS Lambda Function: How to view /tmp storage?

Lambda functions have access to disk space in their own /tmp directories. My question is, where can I visually view the /tmp directory?

I’m attempting to download the files into the /tmp directory to read them, and write a new file to it as well. I actually want see the files I’m working with are getting stored properly in /tmp during execution.

Thank you

Upvotes: 12

Views: 36101

Answers (3)

RandomEli
RandomEli

Reputation: 1557

As previous answers suggested, you might want to create a /tmp directory in S3 bucket and download/upload your temp processing file to this /tmp directory before final clean up.

You can do the following (I'm not showing detailed process here):

import boto 
s3 = boto3.client("s3")
s3.put_object(Bucket=Your_bucket_name,Key=tmp/Your_file_name)

How you download your file from your /tmp is through:

s3.download_file(Your_bucket_name, Your_key_name, Your_file_name)

after you download files and process, you want to upload it again to /tmp through:

s3.upload_file(Your_file_name, Your_bucket_name, Your_key_name)

You can add your /tmp/ in Your_key_name

Then you should be able to list the bucket easily from this sample:

for key in bucket.list():
        print "{name}\t{size}\t{modified}".format(
                name = key.name,
                size = key.size,
                modified = key.last_modified,
                )

Make sure you keep your download and upload asynchronously by this boto async package.

Upvotes: 2

drsromero
drsromero

Reputation: 311

Try to use a S3 bucket to store the file and read it from the AWS Lambda function, you should ensure the AWS Lambda role has access to the S3 bucket.

Upvotes: 1

joarleymoraes
joarleymoraes

Reputation: 1949

You can't 'view' the /tmp directory after the lambda execution has ended.

Lambda works in distributed architecture and after the execution all resources used (including all files stored in /tmp) are disposed.

So if you want to check your files, you might want consider using EC2 or S3.

If you just want to check if the s3 download was successful, during the execution, you can try:

import os
os.path.isfile('/tmp/' + filename)

Upvotes: 13

Related Questions