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

走远了吗. 提交于 2019-12-14 03:56:19

问题


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


回答1:


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)



回答2:


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.




回答3:


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")
client.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.



来源:https://stackoverflow.com/questions/43768290/python-aws-lambda-function-how-to-view-tmp-storage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!