Permission error when deploying a Lambda from a zip file in S3 - [Errno 13] Permission denied

Today I received the following error when trying to deploy from Azure DevOps a lambda to AWS via a zip file in S3:

[ERROR] PermissionError: [Errno 13] Permission denied: '/var/task/'
Traceback (most recent call last):
  File "/var/lang/lib/python3.7/", line 300, in find_module
    with open(file_path, 'rb') as file:

I was compressing the using the Compress-Archive powershell function:

- task: PowerShell@2
    displayName: zip lambda
      targetType: inline
      script: Compress-Archive -Path -DestinationPath
      errorActionPreference: 'stop'

The issues is that the powershell command Compress-Archive, doesn’t archive the files with the correct persmissions and there’s no easy override. The solution I used was to use python, its simple and by default sets the correct permissions:

- task: PythonScript@0
    displayName: zip
      scriptSource: inline
      script: |
        from zipfile import ZipFile
        with ZipFile('', 'w') as zf: