cloud-custodian icon indicating copy to clipboard operation
cloud-custodian copied to clipboard

Getting error AWS Cloud Custodian Mailer with Python 3.11 - [ERROR] Runtime.ImportModuleError: Unable to import module 'periodic': No module named 'jwt' Traceback (most recent cal

Open prasannagithub opened this issue 5 months ago • 4 comments

We have upgraded / repovision AWS Cloud Custodian c7nmailer & getting error, here are the steps

Step 1 - Install Python3.11 in Amazon Linux2 GitHub Runner

yum install python3.11 -y yum install python3.11-pip -y

[root@ _work]# uname -a Linux ip-x.x.x.x 6.1.141-155.222.amzn2023.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Jun 17 10:29:47 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux [root@ _work]# [root@ _work]# python3.11 -V Python 3.11.13 [root@ _work]# python3.11 test.py 3.11.13 (main, Jun 12 2025, 00:00:00) [GCC 11.5.0 20240719 (Red Hat 11.5.0-5)] [root@ _work]#

Step 2 - Deployment step with CD

  • name: Installation run: | python3.11 -m venv custodian . custodian/bin/activate pip install --upgrade pip pip install jinja2 ECPy decorator cryptography PyJWT periodictable || pip3 install --user jinja2 ECPy decorator cryptography PyJWT periodictable pip install c7n c7n-mailer c7n-org c7n-gcp || pip3 install --user c7n c7n-mailer c7n-org c7n-gcp

echo "#### Updating c7n-mailer with the most recent configuration..." . custodian/bin/activate c7n-mailer --config ./mailer/mailerconfig.yml --update-lambda -t ./mailer/templates

Step 3 - Error getting with AWS Mailer Lambda function

2025-07-24T18:01:04.273Z START RequestId: 59f50468-4860-442c-b495-3227a13a1ac2 Version: $LATEST

2025-07-24T18:01:04.274Z
Unknown application error occurred Runtime.ImportModuleError

2025-07-24T18:01:04.274Z END RequestId: 59f50468-4860-442c-b495-3227a13a1ac2

2025-07-24T18:01:04.274Z REPORT RequestId: 59f50468-4860-442c-b495-3227a13a1ac2 Duration: 1406.39 ms Billed Duration: 1407 ms Memory Size: 1024 MB Max Memory Used: 42 MB

2025-07-24T18:03:08.564Z [WARNING] 2025-07-24T18:03:08.564Z LAMBDA_WARNING: Unhandled exception. The most likely cause is an issue in the function code. However, in rare cases, a Lambda runtime update can cause unexpected function behavior. For functions using managed runtimes, runtime updates can be triggered by a function change, or can be applied automatically. To determine if the runtime has been updated, check the runtime version in the INIT_START log entry. If this error correlates with a change in the runtime version, you may be able to mitigate this error by temporarily rolling back to the previous runtime version. For more information, see https://docs.aws.amazon.com/lambda/latest/dg/runtimes-update.html

2025-07-24T18:03:08.574Z [ERROR] Runtime.ImportModuleError: Unable to import module 'periodic': No module named 'jwt' Traceback (most recent call last):

2025-07-24T18:03:08.755Z INIT_REPORT Init Duration: 1472.78 ms Phase: invoke Status: error Error Type: Runtime.ImportModuleError

prasannagithub avatar Jul 24 '25 18:07 prasannagithub

same error here

ecuevasest avatar Aug 08 '25 22:08 ecuevasest

Same error. My workaround:

find the file site-packages/c7n_mailer/deploy.py under your virtualenv directory, or under your python installation. Add "jwt" in CORE_DEPS, e.g.

CORE_DEPS = [
    # core deps
    "jinja2",
    "markupsafe",
    "yaml",
    "ldap3",
    "pyasn1",
    "redis",
    "jwt",
    "jmespath",
    ...

Then rerun c7n-mailer, e.g.:

c7n-mailer --config mailer.yaml --update-lambda

harisfauzi avatar Sep 05 '25 04:09 harisfauzi

I had to roll back to pypi c7n-mailer 0.6.44 to make this work. Otherwise with the latest 0.6.55, I got the same error trying to run the lambda c7n-mailer creates.

I tried adding jwt to the CORE_DEPS list as indicted above, but that then led to another missing requirement with the cryptography package since I was running this on MAC OS and cryptography didn't like the mixing of deploying from Mac OS to AWS Lambda.

Unable to import module 'periodic': /var/task/cryptography/hazmat/bindings/_rust.abi3.so: invalid ELF header"

twstewart42 avatar Sep 16 '25 12:09 twstewart42

hmm.. yeah we upload local libraries when bundling lambdas, so you'll need to be going from a linux host on the same architecture as your target lambda environment.

kapilt avatar Sep 16 '25 18:09 kapilt