为什么 AWS SAM CLI 1.33.0 崩溃,_regex.cpython-38-darwin.so 在 Apple M1 芯片上找不到合适的图像?

Why does AWS SAM CLI 1.33.0 crash with _regex.cpython-38-darwin.so no suitable image found on Apple M1 chips?

今天我更新到 AWS SAM CLI 版本 1.33.0。然后它开始崩溃,在部署过程中出现问题。当我 运行 命令 sam deploysam deploy --guided 时,它抛出以下错误

Traceback (most recent call last):
  File "/opt/homebrew/bin/sam", line 8, in <module>
    sys.exit(cli())
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/samcli/lib/cli_validation/image_repository_validation.py", line 85, in wrapped
    return func(*args, **kwargs)
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/click/decorators.py", line 73, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/samcli/lib/telemetry/metric.py", line 153, in wrapped
    raise exception  # pylint: disable=raising-bad-type
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/samcli/lib/telemetry/metric.py", line 122, in wrapped
    return_value = func(*args, **kwargs)
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/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.33.0/libexec/lib/python3.8/site-packages/samcli/cli/main.py", line 90, in wrapper
    return func(*args, **kwargs)
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/samcli/commands/deploy/command.py", line 216, in cli
    do_cli(
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/samcli/commands/deploy/command.py", line 280, in do_cli
    from samcli.commands.deploy.deploy_context import DeployContext
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/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.33.0/libexec/lib/python3.8/site-packages/samcli/lib/deploy/deployer.py", line 39, in <module>
    from samcli.lib.utils.time import utc_to_timestamp
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/samcli/lib/utils/time.py", line 6, in <module>
    import dateparser
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/dateparser/__init__.py", line 3, in <module>
    from .date import DateDataParser
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/dateparser/date.py", line 6, in <module>
    import regex as re
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/regex/__init__.py", line 1, in <module>
    from .regex import *
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/regex/regex.py", line 419, in <module>
    import regex._regex_core as _regex_core
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/regex/_regex_core.py", line 21, in <module>
    import regex._regex as _regex
ImportError: dlopen(/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/regex/_regex.cpython-38-darwin.so, 2): no suitable image found.  Did find:
        /opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/regex/_regex.cpython-38-darwin.so: code signature in (/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/regex/_regex.cpython-38-darwin.so) not valid for use in process using Library Validation: Trying to load an unsigned library
yohanweerasinghe@Yohans-MacBook-Pro amazon-s3-presigned-urls-aws-sam % sam deploy --guided
Traceback (most recent call last):
  File "/opt/homebrew/bin/sam", line 8, in <module>
    sys.exit(cli())
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/samcli/lib/cli_validation/image_repository_validation.py", line 85, in wrapped
    return func(*args, **kwargs)
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/click/decorators.py", line 73, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/samcli/lib/telemetry/metric.py", line 153, in wrapped
    raise exception  # pylint: disable=raising-bad-type
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/samcli/lib/telemetry/metric.py", line 122, in wrapped
    return_value = func(*args, **kwargs)
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/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.33.0/libexec/lib/python3.8/site-packages/samcli/cli/main.py", line 90, in wrapper
    return func(*args, **kwargs)
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/samcli/commands/deploy/command.py", line 216, in cli
    do_cli(
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/samcli/commands/deploy/command.py", line 280, in do_cli
    from samcli.commands.deploy.deploy_context import DeployContext
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/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.33.0/libexec/lib/python3.8/site-packages/samcli/lib/deploy/deployer.py", line 39, in <module>
    from samcli.lib.utils.time import utc_to_timestamp
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/samcli/lib/utils/time.py", line 6, in <module>
    import dateparser
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/dateparser/__init__.py", line 3, in <module>
    from .date import DateDataParser
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/dateparser/date.py", line 6, in <module>
    import regex as re
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/regex/__init__.py", line 1, in <module>
yohanweerasinghe@Yohans-MacBook-Pro amazon-s3-presigned-urls-aws-sam % sam deploy --guided
Traceback (most recent call last):
  File "/opt/homebrew/bin/sam", line 8, in <module>
    sys.exit(cli())
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/samcli/lib/cli_validation/image_repository_validation.py", line 85, in wrapped
    return func(*args, **kwargs)
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/click/decorators.py", line 73, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/samcli/lib/telemetry/metric.py", line 153, in wrapped
    raise exception  # pylint: disable=raising-bad-type
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/samcli/lib/telemetry/metric.py", line 122, in wrapped
    return_value = func(*args, **kwargs)
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/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.33.0/libexec/lib/python3.8/site-packages/samcli/cli/main.py", line 90, in wrapper
    return func(*args, **kwargs)
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/samcli/commands/deploy/command.py", line 216, in cli
    do_cli(
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/samcli/commands/deploy/command.py", line 280, in do_cli
    from samcli.commands.deploy.deploy_context import DeployContext
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/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.33.0/libexec/lib/python3.8/site-packages/samcli/lib/deploy/deployer.py", line 39, in <module>
    from samcli.lib.utils.time import utc_to_timestamp
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/samcli/lib/utils/time.py", line 6, in <module>
    import dateparser
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/dateparser/__init__.py", line 3, in <module>
    from .date import DateDataParser
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/dateparser/date.py", line 6, in <module>
    import regex as re
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/regex/__init__.py", line 1, in <module>
yohanweerasinghe@Yohans-MacBook-Pro amazon-s3-presigned-urls-aws-sam % sam deploy --guided
Traceback (most recent call last):
  File "/opt/homebrew/bin/sam", line 8, in <module>
    sys.exit(cli())
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/samcli/lib/cli_validation/image_repository_validation.py", line 85, in wrapped
    return func(*args, **kwargs)
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/click/decorators.py", line 73, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/samcli/lib/telemetry/metric.py", line 153, in wrapped
    raise exception  # pylint: disable=raising-bad-type
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/samcli/lib/telemetry/metric.py", line 122, in wrapped
    return_value = func(*args, **kwargs)
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/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.33.0/libexec/lib/python3.8/site-packages/samcli/cli/main.py", line 90, in wrapper
    return func(*args, **kwargs)
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/samcli/commands/deploy/command.py", line 216, in cli
    do_cli(
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/samcli/commands/deploy/command.py", line 280, in do_cli
    from samcli.commands.deploy.deploy_context import DeployContext
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/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.33.0/libexec/lib/python3.8/site-packages/samcli/lib/deploy/deployer.py", line 39, in <module>
    from samcli.lib.utils.time import utc_to_timestamp
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/samcli/lib/utils/time.py", line 6, in <module>
    import dateparser
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/dateparser/__init__.py", line 3, in <module>
    from .date import DateDataParser
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/dateparser/date.py", line 6, in <module>
    import regex as re
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/regex/__init__.py", line 1, in <module>
    from .regex import *
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/regex/regex.py", line 419, in <module>
    import regex._regex_core as _regex_core
  File "/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/regex/_regex_core.py", line 21, in <module>
    import regex._regex as _regex
ImportError: dlopen(/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/regex/_regex.cpython-38-darwin.so, 2): no suitable image found.  Did find:
        /opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/regex/_regex.cpython-38-darwin.so: code signature in (/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/regex/_regex.cpython-38-darwin.so) not valid for use in process using Library Validation: Trying to load an unsigned library

我在MacOS Big Sir 11.6, M1 Chip pro.

我该如何解决这个问题?或者可能恢复到以前版本的 SAM?

更新

这是命令 brew info aws-sam-cli

的输出
aws/tap/aws-sam-cli: stable 1.33.0, HEAD
AWS SAM CLI  is a tool for local development and testing of Serverless applications
https://github.com/awslabs/aws-sam-cli/
Conflicts with:
  aws-sam-cli-rc (because both install the 'sam' binary)
/opt/homebrew/Cellar/aws-sam-cli/1.33.0 (5,872 files, 108.7MB) *
  Built from source on 2021-10-16 at 13:50:40
From: https://github.com/aws/homebrew-tap/blob/HEAD/Formula/aws-sam-cli.rb
==> Dependencies
Required: python@3.8 ✔
==> Options
--HEAD
    Install HEAD version

请检查下面的 brew search aws-sam-cli 命令

的输出
==> Formulae
aws/tap/aws-sam-cli ✔                    aws/tap/aws-sam-cli-nightly
aws/tap/aws-sam-cli-beta-acc             aws/tap/aws-sam-cli-rc
aws/tap/aws-sam-cli-beta-cdk             aws-sam-cli-rc

我们已经确定了问题并正在修复中。问题是正则表达式的一个版本。我们需要固定到特定版本 (2021.9.30),因为后来的版本在 M1 上有问题。新版本的 CLI 将解决这个问题。

目前,解决方法是

  1. 对于 brew 安装:/opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/bin/pip3 install regex==2021.9.30
  2. 对于 PIP 安装:pip install regex==2021.9.30

您可以通过codesign签署regex.so:

xcrun codesign --sign - /opt/homebrew/Cellar/aws-sam-cli/1.33.0/libexec/lib/python3.8/site-packages/regex/_regex.cpython-38-darwin.so