我目前正在開發一些 lambdas 來在 S3 上托管的文本檔案上執行 Python 腳本。
這些文本檔案可能非常大(最大 1GB),據我所知,Lambda 有一個 512Mb 的 tmp 目錄,所以我假設我只能加載一個 512MB 的檔案。
但我也讀到它有 10240MB 的函式記憶體分配。
那么我可以使用 open() 方法從 S3 打開一個 1GB 的檔案嗎?
如果有人也可以給我一些關于 tmp 檔案夾和記憶體的區別的見解==> 如果記憶體是 10GB,為什么要使用 512MB 的 tmp 檔案夾?
非常感謝!
有一個偉大的 2022 年
uj5u.com熱心網友回復:
您可以使用常規get_object,而無需將其寫入/tmp:
s3 = boto3.client('s3')
def lambda_handler(event, context):
response = s3.get_object(
Bucket='your-bucket',
Key='your-key'
)
# get the content of the file as bytes
text_bytes = response['Body'].read()
# change it to string
text_str = text_bytes.decode()
# process as you want the text_str
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/408998.html
標籤:
上一篇:嘗試通過將aws憑據作為變數傳遞給氣流宏來使用boto3連接到awss3
下一篇:呼叫GetObject時拒絕訪問
