aws-cloudformation / aws-cloudformation-samples

Apache License 2.0
134 stars 55 forks source link

[BUG]: ImportError on python examples #85

Closed chamcca closed 1 year ago

chamcca commented 1 year ago

Python example fails to execute and unit tests fail with the error:

ImportError: cannot import name 'verify_interface' from 'cryptography.utils'

mrinaudo-aws commented 1 year ago

Hello @chamcca - this issue is not directly related to this sample, but with a dependency consumed with the cloudformation-cli-python-plugin that you use as part of this sample; see this related issue instead, that already has a fix merged, but the new version of the plugin is not yet released. Looking into that fix, it does not pin cryptography to a lower version, but rather uses a new version of the aws-encryption-sdk (see the details on the merged PR). In the interim, mimicking that intent, temporarily adding aws-encryption-sdk==3.1.1 to your local copy of the requirements.txt file should suffice to package this sample correctly.

mrinaudo-aws commented 1 year ago

Closing the issue and the PR accordingly, per above.

mrinaudo-aws commented 1 year ago

See also this issue.

chamcca commented 1 year ago

got it. that works, thanks for the update. i should have started there

mrinaudo-aws commented 1 year ago

No worries at all! Thank you for jumping in. The updated lib (and bumped up version number) should cause the cloudformation-cli-python-lib>=2.1.3 current line in the requirements.txt on this sample to consume from the latest, to-be-released version of cloudformation-cli-python-lib, whose aws-encryption-sdk version I see it to be set to 3.1.1 as per here. With this holding true, the long-term need for forcing that dependency on a target extension (for example, this sample resource type) would not be needed, as it should be inherited by the latest, to-be-released version of that library.

mrinaudo-aws commented 1 year ago

Hi @chamcca - the Python plugin and lib are now updated. I used pip to upgrade them on my machine, where I now have aws-encryption-sdk-3.1.1, cloudformation-cli-python-lib-2.1.16, and cloudformation-cli-python-plugin-2.1.8. With no changes to my requirements.txt file for the sample resource type in question (meaning, no need to add the temporary line mentioned earlier), I was able to rebuild (cfn generate && cfn submit --dry-run), and then to successfully run contract tests (13 passed, 2 skipped, 9 deselected, 1 warning in 164.10s (0:02:44), and 13 passed, 2 skipped, 9 deselected, 1 warning in 151.41s (0:02:31)). You as well should then be able to expunge the aforementioned line in your requirements.txt file, as it is now part of the "inherited" dependency; what I have now is only:

% cat requirements.txt 
cloudformation-cli-python-lib>=2.1.3

Thank you!

chamcca commented 1 year ago

just confirmed it. works great, thanks for the update