I am trying to migrate an AWS Lambda function written in Python to CF that
- unzips on-the-fly and read line-by-line
- performs some light transformations on each line
- write output (a line at a time or chunks) uncompressed to GCS
The output is > 2GB - but slightly less than 3GB so it fits in Lambda, just.
Well, it seems impossible or way more involved in GCP:
- uncompressed cannot fit in memory or
/tmp- limited to 2048MB as of writing this - so Python Client libupload_from_file(or_filename) cannot be used - there is this official paper but to my surprise, it's referring to
boto, a library initially designed forAWS S3, and a quite outdated one sinceboto3is out for some time. No genuineGCPmethod to stream write or read - Node.js has a simple
createWriteStream()- nice article here btw - but no equivalent one-liner in Python - Resumable media upload sounds like it but lot of code for something handled in Node much easier
- AppEngine had cloudstorage but not available outside of it - and obsolete
- little to no example out there on a working wrapper for writing text/plain data line-by-line as if
GCSwas a local filesystem. This is not limited toCloud Functionsand a lacking feature of the Python Client library, but it is more acute in CF due the resource constraints. Btw, I was part of a discussion to add a writeable IOBase function but it had no traction. - obviously using a VM or
DataFloware out of question for the task at hand.
In my mind, stream (or stream-like) reading/writing from cloud-based storage should even be included in the Python standard library.
As recommended back then, one can still use GCSFS, which behind the scenes commits the upload in chunks for you while you are writing stuff to a FileObj.
The same team wrote s3fs. I don't know for Azure.
AFAIC, I will stick to AWS Lambda as the output can fit in memory - for now - but multipart upload is the way to go to support any output size with a minimum of memory.
Thoughts or alternatives ?