title: Issues with AWS Lambda Docker Container (permission denied)
body: <p>I am deploying a Docker container with AWS Lambda which executes a machine learning model. But whenever I attempt to load the saved checkpoints, I am getting a permission denied message when attempting to read the local filesystem or a no directory found based on where I am storing the model...?</p>
  <p>Here is the relevant Dockerfile:</p>
  <pre><code>FROM public.ecr.aws/lambda/python:3.8
  
  # copy requirements.txt file to the container
  COPY requirements.txt ./
  
  # upgrade pip and install the python requirements from requirements.txt
  RUN python3.8 -m pip install \
          --upgrade pip
  RUN python3.8 -m pip install \
          -r requirements.txt
  
  # Copy function code
  COPY app.py ./
  
  # Install the runtime interface client
  RUN python3.8 -m pip install \
          awslambdaric
  
  # clean up image for small container
  RUN find . -type d -name &quot;tests&quot; -exec rm -rf {} +
  RUN find . -type d -name &quot;__pycache__&quot; -exec rm -rf {} +
  RUN find . -type d -name &quot;include&quot; -exec rm -rf {} +
  RUN rm -rf ./{caffe2,wheel,wheel-*,pkg_resources,boto*,aws*,pip,pip-*,pipenv,setuptools}
  RUN rm -rf ./{*.egg-info,*.dist-info}
  RUN find . -name \*.pyc -delete
  RUN find . -type d -name &quot;test&quot; -exec rm -rf {} +
  RUN ls -R -al
  
  # update linux libraries
  RUN yum update -y
  
  # install python3 and unzip
  RUN yum install -y python3 unzip
  
  # pull model files
  RUN mkdir ./model
  RUN curl https://somewhere.com/model.zip -o ./model/model.zip
  RUN unzip ./model/model.zip -d ./model
  RUN chmod 644 ./model
  RUN chmod -R 644 ./model/*
  RUN rm ./model/model.zip
  
  WORKDIR ./
  ENTRYPOINT [ &quot;python3&quot;, &quot;-m&quot;, &quot;awslambdaric&quot; ]
  CMD [ &quot;app.lambda_handler&quot; ]
  </code></pre>
  <p>And the app.py:</p>
  <pre><code>from __future__ import print_function
  import json, time
  import urllib.request
  from jose import jwk, jwt
  from jose.utils import base64url_decode
  from sentence_transformers import SentenceTransformer, util
  
  model = ModelFunction('/model')
  
  
  def lambda_handler(event, context):
  
      body = json.loads(event['body'])
  
      token = body['jwttoken']
      utterance = body['utterance']
      comparestring = body['comparestring']
  
      # generate embeddings for each phrase
      embeddings1 = model.encode(utterance, convert_to_tensor=True)
      embeddings2 = model.encode(comparestring, convert_to_tensor=True)
  
      # compute score
      score = util.embeddings(embeddings1, embeddings2)
  
      # output score
      print(&quot;Score:&quot;)
      print(score.item())
  
      return {
          &quot;statusCode&quot;: 200,
          &quot;score&quot;: json.dums(score.item())
      }
  
      # the following is useful to make this script executable in both
      # AWS Lambda and any other local environments
  if __name__ == '__main__':
      event = {
          'token': '',
          'email': 'somewhere@somewhere.com'}
      lambda_handler(event, None)
  </code></pre>
  <p>A couple of the relevant error messages:</p>
  <pre><code>[ERROR] PermissionError: [Errno 13] Permission denied: './model/modules.json'
  Traceback (most recent call last):
    File &quot;/var/lang/lib/python3.8/imp.py&quot;, line 234, in load_module
      return load_source(name, filename, file)
    File &quot;/var/lang/lib/python3.8/imp.py&quot;, line 171, in load_source
      module = _load(spec)
    File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 702, in _load
    File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 671, in _load_unlocked
    File &quot;&lt;frozen importlib._bootstrap_external&gt;&quot;, line 848, in exec_module
    File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 219, in _call_with_frames_removed
    File &quot;/var/task/app.py&quot;, line 8, in &lt;module&gt;
      model = model('./model')
    File &quot;/var/lang/lib/python3.8/site-packages/model/model.py&quot;, line 115, in __init__
      with open(os.path.join(model_path, 'modules.json')) as fIn:
  </code></pre>
  <p>and</p>
  <pre><code>[ERROR] FileNotFoundError: [Errno 2] No such file or directory: '/home/sbx_user1051/.cache/model'
  Traceback (most recent call last):
    File &quot;/var/lang/lib/python3.8/imp.py&quot;, line 234, in load_module
      return load_source(name, filename, file)
    File &quot;/var/lang/lib/python3.8/imp.py&quot;, line 171, in load_source
      module = _load(spec)
    File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 702, in _load
    File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 671, in _load_unlocked
    File &quot;&lt;frozen importlib._bootstrap_external&gt;&quot;, line 848, in exec_module
    File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 219, in _call_with_frames_removed
    File &quot;/var/task/app.py&quot;, line 8, in &lt;module&gt;
      model = model('/model')
    File &quot;/var/lang/lib/python3.8/site-packages/model/model.py&quot;, line 101, in __init__
      shutil.rmtree(model_path)
    File &quot;/var/lang/lib/python3.8/shutil.py&quot;, line 709, in rmtree
      onerror(os.lstat, path, sys.exc_info())
    File &quot;/var/lang/lib/python3.8/shutil.py&quot;, line 707, in rmtree
      orig_st = os.lstat(path)
  </code></pre>
  <p>Any ideas? I think I am not storing the model checkpoints in the correct directory? The above logs have been somewhat scrubbed due to NDA etc.</p>