aws / aws-sam-cli

CLI tool to build, test, debug, and deploy Serverless applications using AWS SAM
https://aws.amazon.com/serverless/sam/
Apache License 2.0
6.47k stars 1.16k forks source link

Bug: sam deploy - ModuleNotFoundError (pytz) #6125

Closed christoph-zero closed 8 months ago

christoph-zero commented 9 months ago

Description:

After upgrade aws-sam-cli to 1.99.0 via brew upgrade the sam deploy command fails with message:

Error: No module named 'pytz'
Traceback:
  File "/opt/homebrew/Cellar/aws-sam-cli/1.99.0/libexec/lib/python3.12/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.99.0/libexec/lib/python3.12/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.99.0/libexec/lib/python3.12/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.99.0/libexec/lib/python3.12/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.99.0/libexec/lib/python3.12/site-packages/samcli/cli/cli_config_file.py", line 297, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.99.0/libexec/lib/python3.12/site-packages/samcli/lib/cli_validation/image_repository_validation.py", line 110, in wrapped
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.99.0/libexec/lib/python3.12/site-packages/click/decorators.py", line 92, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.99.0/libexec/lib/python3.12/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.99.0/libexec/lib/python3.12/site-packages/samcli/lib/telemetry/metric.py", line 184, in wrapped
    raise exception  # pylint: disable=raising-bad-type
    ^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.99.0/libexec/lib/python3.12/site-packages/samcli/lib/telemetry/metric.py", line 149, in wrapped
    return_value = func(*args, **kwargs)
                   ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.99.0/libexec/lib/python3.12/site-packages/samcli/lib/utils/version_checker.py", line 42, in wrapped
    actual_result = func(*args, **kwargs)
                    ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.99.0/libexec/lib/python3.12/site-packages/samcli/cli/main.py", line 95, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.99.0/libexec/lib/python3.12/site-packages/samcli/commands/_utils/cdk_support_decorators.py", line 39, in wrapped
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.99.0/libexec/lib/python3.12/site-packages/samcli/commands/_utils/command_exception_handler.py", line 88, in wrapper_command_exception_handler
    raise ex
  File "/opt/homebrew/Cellar/aws-sam-cli/1.99.0/libexec/lib/python3.12/site-packages/samcli/commands/_utils/command_exception_handler.py", line 68, in wrapper_command_exception_handler
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.99.0/libexec/lib/python3.12/site-packages/samcli/commands/deploy/command.py", line 200, in cli
    do_cli(
  File "/opt/homebrew/Cellar/aws-sam-cli/1.99.0/libexec/lib/python3.12/site-packages/samcli/commands/deploy/command.py", line 267, in do_cli
    from samcli.commands.deploy.deploy_context import DeployContext
  File "/opt/homebrew/Cellar/aws-sam-cli/1.99.0/libexec/lib/python3.12/site-packages/samcli/commands/deploy/deploy_context.py", line 32, in <module>
    from samcli.lib.deploy.deployer import Deployer
  File "/opt/homebrew/Cellar/aws-sam-cli/1.99.0/libexec/lib/python3.12/site-packages/samcli/lib/deploy/deployer.py", line 42, in <module>
    from samcli.lib.utils.time import utc_to_timestamp
  File "/opt/homebrew/Cellar/aws-sam-cli/1.99.0/libexec/lib/python3.12/site-packages/samcli/lib/utils/time.py", line 7, in <module>
    import dateparser
  File "/opt/homebrew/Cellar/aws-sam-cli/1.99.0/libexec/lib/python3.12/site-packages/dateparser/__init__.py", line 3, in <module>
    from .date import DateDataParser
  File "/opt/homebrew/Cellar/aws-sam-cli/1.99.0/libexec/lib/python3.12/site-packages/dateparser/date.py", line 10, in <module>
    from dateparser.date_parser import date_parser
  File "/opt/homebrew/Cellar/aws-sam-cli/1.99.0/libexec/lib/python3.12/site-packages/dateparser/date_parser.py", line 6, in <module>
    from .utils import strip_braces, apply_timezone, localize_timezone
  File "/opt/homebrew/Cellar/aws-sam-cli/1.99.0/libexec/lib/python3.12/site-packages/dateparser/utils/__init__.py", line 9, in <module>
    from pytz import UTC, timezone, UnknownTimeZoneError

Steps to reproduce:

Observed result:

Expected result:

No Python module errors

Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

  1. OS: macOS 14.0 (Sonoma)
  2. sam --version: SAM CLI, version 1.99.0
  3. AWS region: eu-central-1
# Paste the output of `sam --info` here
{
  "version": "1.99.0",
  "system": {
    "python": "3.8.13",
    "os": "macOS-14.0-arm64-arm-64bit"
  },
  "additional_dependencies": {
    "docker_engine": "24.0.6",
    "aws_cdk": "2.102.0 (build 2abc59a)",
    "terraform": "Not available"
  },
  "available_beta_feature_env_vars": [
    "SAM_CLI_BETA_FEATURES",
    "SAM_CLI_BETA_BUILD_PERFORMANCE",
    "SAM_CLI_BETA_TERRAFORM_SUPPORT",
    "SAM_CLI_BETA_RUST_CARGO_LAMBDA"
  ]
}
sebastian-zero commented 9 months ago

Same issue on Linux using brew community version of aws-sam-cli 1.99.

abhiyankhanal commented 9 months ago

In my case I downgraded the version and it worked. If someone knows how to solve this problem in v1.99.0 pleaseet me know

icedrone commented 9 months ago

In my case I downgraded the version and it worked. If someone knows how to solve this problem in v1.99.0 pleaseet me know @abhiyankhanal

can you share how you downgraded?

joshbegin commented 9 months ago

I found this similar issue on the homebrew repo: https://github.com/Homebrew/homebrew-core/issues/151657 Based on the responses, I resolved the issue (for me, at least) by running: brew update && brew upgrade brew reinstall python-pytz You have have to uninstall/reinstall sam after that, but just these two commands worked for me.

hnnasit commented 9 months ago

Hello all, as mentioned in https://github.com/aws/aws-sam-cli/issues/5613 installation through homebrew is now maintained by the community-managed formula. Thanks @joshbegin for linking a similar issue on the homebrew repository. We recommend installing SAM CLI using the installers that we maintain. More information for installation can be found in https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/install-sam-cli.html.

matejpokorny commented 9 months ago

The community managed version 1.99 did not help. Official installer mentioned by @hnnasit fixed the problem for me

christoph-zero commented 9 months ago

Thank you @joshbegin and @hnnasit. Is there any fix planned from this community managed package?

github-actions[bot] commented 8 months ago

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.