- Newest
- Most votes
- Most comments
The issue you're facing is related to the read-only file system in AWS Lambda. While you've correctly set some environment variables to use the /tmp directory, which is writable in Lambda, it seems that the SentenceTransformer or wandb library might be trying to write to a different location.
To address this problem, you can try the following steps:
-
Ensure that all necessary environment variables are set to use the /tmp directory. In addition to the ones you've already set, you might want to add:
os.environ['TRANSFORMERS_CACHE'] = '/tmp' os.environ['XDG_CACHE_HOME'] = '/tmp' -
Create the necessary directories in /tmp before initializing the model:
os.makedirs('/tmp/huggingface', exist_ok=True) os.makedirs('/tmp/wandb', exist_ok=True) -
If possible, try to configure the SentenceTransformer to use a specific cache directory in /tmp:
from sentence_transformers import SentenceTransformer model = SentenceTransformer(model_name_or_path, cache_folder='/tmp/sentence_transformers') -
For wandb, you can try setting the WANDB_DIR environment variable:
os.environ['WANDB_DIR'] = '/tmp/wandb' -
If the issue persists, you might need to investigate which specific file or directory the libraries are trying to access. You can add more detailed logging to track file operations and identify the problematic paths.
-
Consider using a Lambda layer to include your dependencies, which might help manage the file system access more effectively.
Remember that Lambda has a limit on the /tmp directory size (usually around 512 MB), so ensure your model and related files fit within this limit.
If these steps don't resolve the issue, you might need to consider using a custom container for your Lambda function, which would give you more control over the environment and file system.
Lastly, make sure you're using the latest versions of the sentence-transformers and wandb libraries, as newer versions might have better compatibility with serverless environments like AWS Lambda.
Sources
how to work around directory permissions in aws lambda? | AWS re:Post
Including a transformer model in the container for AWS Lambda | AWS re:Post
answered 2 years ago
Relevant content
asked 2 years ago
asked 4 months ago
asked 3 years ago
- AWS OFFICIALUpdated 5 years ago

Ι have made most of these and nothing work. Something else is going on!