Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SAM build stopped working | AttributeError: module 'lib' has no attribute 'OpenSSL_add_all_algorithms' #64

Closed
intrealm opened this issue Jan 2, 2023 · 15 comments

Comments

@intrealm
Copy link

intrealm commented Jan 2, 2023

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.
@MatthewCochrane
Copy link

I have the same issue.

Run sam build --template ${SAM_TEMPLATE} --use-container

Traceback (most recent call last):
  File "/home/runner/work/_temp/setup-sam-xv34Es/bin/sam", line 8, in <module>
    sys.exit(cli())
             ^^^^^
  File "/home/runner/work/_temp/setup-sam-xv34Es/.venv/lib/python3.11/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/_temp/setup-sam-xv34Es/.venv/lib/python3.11/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/home/runner/work/_temp/setup-sam-xv34Es/.venv/lib/python3.11/site-packages/click/core.py", line 1651, in invoke
    cmd_name, cmd, args = self.resolve_command(ctx, args)
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/_temp/setup-sam-xv34Es/.venv/lib/python3.11/site-packages/click/core.py", line 1698, in resolve_command
    cmd = self.get_command(ctx, cmd_name)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/_temp/setup-sam-xv34Es/.venv/lib/python3.11/site-packages/samcli/cli/command.py", line 133, in get_command
    mod = importlib.import_module(pkg_name)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.11.1/x64/lib/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1149, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/home/runner/work/_temp/setup-sam-xv34Es/.venv/lib/python3.11/site-packages/samcli/commands/build/__init__.py", line 6, in <module>
    from .command import cli  # noqa
    ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/_temp/setup-sam-xv34Es/.venv/lib/python3.11/site-packages/samcli/commands/build/command.py", line 12, in <module>
    from samcli.commands._utils.options import (
  File "/home/runner/work/_temp/setup-sam-xv34Es/.venv/lib/python3.11/site-packages/samcli/commands/_utils/options.py", line [21](https://github.com/MatthewCochrane/aws-sam-test/actions/runs/3820822995/jobs/6499410576#step:5:22), in <module>
    from samcli.commands._utils.template import get_template_data, TemplateNotFoundException
  File "/home/runner/work/_temp/setup-sam-xv34Es/.venv/lib/python3.11/site-packages/samcli/commands/_utils/template.py", line 10, in <module>
    from botocore.utils import set_value_from_jmespath
  File "/home/runner/work/_temp/setup-sam-xv34Es/.venv/lib/python3.11/site-packages/botocore/utils.py", line 37, in <module>
    import botocore.httpsession
  File "/home/runner/work/_temp/setup-sam-xv34Es/.venv/lib/python3.11/site-packages/botocore/httpsession.py", line 46, in <module>
    from urllib3.contrib.pyopenssl import (
  File "/home/runner/work/_temp/setup-sam-xv34Es/.venv/lib/python3.11/site-packages/urllib3/contrib/pyopenssl.py", line 50, in <module>
    import OpenSSL.crypto
  File "/home/runner/work/_temp/setup-sam-xv34Es/.venv/lib/python3.11/site-packages/OpenSSL/__init__.py", line 8, in <module>
    from OpenSSL import crypto, SSL
  File "/home/runner/work/_temp/setup-sam-xv34Es/.venv/lib/python3.11/site-packages/OpenSSL/crypto.py", line 3[26](https://github.com/MatthewCochrane/aws-sam-test/actions/runs/3820822995/jobs/6499410576#step:5:27)8, in <module>
    _lib.OpenSSL_add_all_algorithms()
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'lib' has no attribute 'OpenSSL_add_all_algorithms'
Error: Process completed with exit code 1.

@pedro-sphere
Copy link

From what i can see while troubleshooting, the following package got an update on 01.01.2023:
cryptography-39.0.0
As of Saturday(31.12) it was working perfectly with:
cryptography-38.0.4

On the libry portal you can see the release notes:
https://cryptography.io/en/latest/changelog/

Is there a way to fix the version # for this action??

BR
Pedro

@hoffa
Copy link
Contributor

hoffa commented Jan 2, 2023

Relevant: aws/aws-sam-cli#4527

Is there a way to fix the version # for this action??

You can change the version of SAM CLI that it installs using the version property, e.g.:

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

@nszeitli
Copy link

nszeitli commented Jan 2, 2023

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

@pedro-sphere
Copy link

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

@nszeitli
Copy link

nszeitli commented Jan 2, 2023

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

@pedro-sphere
Copy link

PERFECT @nszeitli !!! It worked!
That was the bit I was missing! :-) I had to set in the venv! :-)
Working for now!
Thanks
Pedro

@hoffa
Copy link
Contributor

hoffa commented Jan 2, 2023

@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.

@dgokcin
Copy link

dgokcin commented Jan 2, 2023

having the same issue. any estimates on when will this be fixed?

I do not want to pin the version for all lambdas in our infrastructure

thanks

@LautaroJayat
Copy link

happy new year!

@altaurog
Copy link

altaurog commented Jan 3, 2023

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"

@aahung
Copy link
Contributor

aahung commented Jan 6, 2023

Fixed in SAM CLI v1.68.0

@hoffa
Copy link
Contributor

hoffa commented Mar 2, 2023

FYI you can now avoid issues such as these with use-installer:

- uses: aws-actions/setup-sam@v2
  with:
    use-installer: true

It uses the native installers directly, which is a lot faster and doesn't require to have Python installed.

@altaurog
Copy link

altaurog commented Mar 2, 2023

FYI you can now avoid issues such as these with use-installer:

- uses: aws-actions/setup-sam@v2
  with:
    use-installer: true

It uses the native installers directly, which is a lot faster and doesn't require to have Python installed.

Can you clarify please @hoffa what is the native installer?

@hoffa
Copy link
Contributor

hoffa commented Mar 2, 2023

@altaurog They're self-contained packages of SAM CLI (i.e. includes everything needed to run it, including Python). They're the suggested installation method for Linux. Under the hood PyInstaller is used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants