setup-sam: SAM build stopped working | AttributeError: module 'lib' has no attribute 'OpenSSL_add_all_algorithms'

failing (was working a week ago) Run sam build --use-container

  File "/home/ubuntu/actions-runner/_work/_temp/setup-sam-jpw4ru/bin/sam", line 8, in <module>
    sys.exit(cli())
  File "/home/ubuntu/actions-runner/_work/_temp/setup-sam-jpw4ru/.venv/lib/python3.8/site-packages/click/core.py", line [1](https://github.com/oziva-in/oziva-functions/actions/runs/3820580200/jobs/6499156404#step:10:1)130, in __call__
    return self.main(*args, **kwargs)
  File "/home/ubuntu/actions-runner/_work/_temp/setup-sam-jpw4ru/.venv/lib/python3.8/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/home/ubuntu/actions-runner/_work/_temp/setup-sam-jpw4ru/.venv/lib/python3.8/site-packages/click/core.py", line 16[51](https://github.com/oziva-in/oziva-functions/actions/runs/3820580200/jobs/6499156404#step:10:51), in invoke
    cmd_name, cmd, args = self.resolve_command(ctx, args)
  File "/home/ubuntu/actions-runner/_work/_temp/setup-sam-jpw4ru/.venv/lib/python3.8/site-packages/click/core.py", line 1698, in resolve_command
    cmd = self.get_command(ctx, cmd_name)
  File "/home/ubuntu/actions-runner/_work/_temp/setup-sam-jpw4ru/.venv/lib/python3.8/site-packages/samcli/cli/command.py", line 133, in get_command
    mod = importlib.import_module(pkg_name)
  File "/home/ubuntu/actions-runner/_work/_tool/Python/3.8.15/x[64](https://github.com/oziva-in/oziva-functions/actions/runs/3820580200/jobs/6499156404#step:10:65)/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line [67](https://github.com/oziva-in/oziva-functions/actions/runs/3820580200/jobs/6499156404#step:10:68)1, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 843, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/ubuntu/actions-runner/_work/_temp/setup-sam-jpw4ru/.venv/lib/python3.8/site-packages/samcli/commands/build/__init__.py", line 6, in <module>
    from .command import cli  # noqa
  File "/home/ubuntu/actions-runner/_work/_temp/setup-sam-jpw4ru/.venv/lib/python3.8/site-packages/samcli/commands/build/command.py", line 12, in <module>
    from samcli.commands._utils.options import (
  File "/home/ubuntu/actions-runner/_work/_temp/setup-sam-jpw4ru/.venv/lib/python3.8/site-packages/samcli/commands/_utils/options.py", line 21, in <module>
    from samcli.commands._utils.template import get_template_data, TemplateNotFoundException
  File "/home/ubuntu/actions-runner/_work/_temp/setup-sam-jpw4ru/.venv/lib/python3.8/site-packages/samcli/commands/_utils/template.py", line 10, in <module>
    from botocore.utils import set_value_from_jmespath
  File "/home/ubuntu/actions-runner/_work/_temp/setup-sam-jpw4ru/.venv/lib/python3.8/site-packages/botocore/utils.py", line 37, in <module>
    import botocore.httpsession
  File "/home/ubuntu/actions-runner/_work/_temp/setup-sam-jpw4ru/.venv/lib/python3.8/site-packages/botocore/httpsession.py", line 46, in <module>
    from urllib3.contrib.pyopenssl import (
  File "/home/ubuntu/actions-runner/_work/_temp/setup-sam-jpw4ru/.venv/lib/python3.8/site-packages/urllib3/contrib/pyopenssl.py", line 50, in <module>
    import OpenSSL.crypto
  File "/home/ubuntu/actions-runner/_work/_temp/setup-sam-jpw4ru/.venv/lib/python3.8/site-packages/OpenSSL/__init__.py", line 8, in <module>
    from OpenSSL import crypto, SSL
  File "/home/ubuntu/actions-runner/_work/_temp/setup-sam-jpw4ru/.venv/lib/python3.8/site-packages/OpenSSL/crypto.py", line 32[68](https://github.com/oziva-in/oziva-functions/actions/runs/3820580200/jobs/6499156404#step:10:69), in <module>
    _lib.OpenSSL_add_all_algorithms()
AttributeError: module 'lib' has no attribute 'OpenSSL_add_all_algorithms'
Error: Process completed with exit code 1.

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 20
  • Comments: 15 (5 by maintainers)

Commits related to this issue

Most upvoted comments

Thanks hoffa I ended up asking chat.openai to fix and it worked with some tweaks:

    - name: Temp fix SAM crypto
       run: |
         # Find the directory using a wildcard pattern
         pwd
         cd /home/runner/work/_temp/
         ls
         setup_sam_dir=$(find . -type d -name "setup-sam-*" | head -n 1)

         # Check if the directory was found
         if [ -z "$setup_sam_dir" ]; then
           # No directory was found
           echo "Directory not found"
         else
           # Directory was found
           echo "Found directory: $setup_sam_dir"

           # Activate the virtual environment
           source "/home/runner/work/_temp/$setup_sam_dir/.venv/bin/activate"
           echo "Virtual environment activated"
           pip install cryptography==38.0.4
         fi

happy new year!

@nszeitli Nice!

For posterity, you could also try:

- uses: aws-actions/setup-sam@v2
  with:
    version: 1.59.0

I haven’t tested but IIRC cryptography is a transitive dependency of pyOpenSSL that was added along OIDC support in AWS SAM CLI 1.60.0.

PERFECT @nszeitli !!! It worked! That was the bit I was missing! πŸ˜ƒ I had to set in the venv! πŸ˜ƒ Working for now! Thanks Pedro

As I posted here, you can also fix with an additional step after aws-actions/setup-sam:

      - name: sam fix https://github.com/aws/aws-sam-cli/issues/4527
        run: $(dirname $(readlink $(which sam)))/pip install --force-reinstall "cryptography==38.0.4"

Hi @hoffa ,

Thanks, but the issues seems to be on the new cryptography-39.0.0 package. Even if I force to use a specific SAM version, it has a version constraint like this:

Collecting cryptography>=35.0
  Downloading cryptography-39.0.0-cp36-abi3-manylinux_2_28_x86_64.whl (4.2 MB)

At the moment I am trying to uninstall the 39 version and revert to the 38.04 but I must confess I am no python expert. πŸ˜ƒ

I tried to run this after the aws-actions/setup-sam@v2:

pip uninstall cryptography
pip install 'cryptography==38.0.4'

To uninstall the 39 and install 38.0.4…

The issue is that I am getting: WARNING: Skipping cryptography as it is not installed.

I am certainly missing something. Trying to figure out.

BR Pedro

Have a look at my script, you have to change the venv not the machine default python

Fixed in SAM CLI v1.68.0