我在 python 中有一个 lambda 函数,它运行良好一段时间。 我尝试将 CloudFront keyValueStore 添加到该函数,但在本地我遇到了错误:
[ERROR] MissingDependencyException: Missing Dependency: This operation requires an additional dependency. Use pip install botocore[crt] before proceeding.
Traceback (most recent call last):
File "/var/task/lambda_function.py", line 56, in lambda_handler
upload_files(env, client, zip_file_path, parts[-1], user_name)
File "/var/task/lambda_function.py", line 125, in upload_files
update_keyvaluestore(env, client, values)
File "/var/task/lambda_function.py", line 239, in update_keyvaluestore
e_tag = cloudfront_keyvaluestore_client.describe_key_value_store(
File "/var/task/botocore/client.py", line 565, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/var/task/botocore/client.py", line 967, in _make_api_call
) = self._resolve_endpoint_ruleset(
File "/var/task/botocore/client.py", line 1130, in _resolve_endpoint_ruleset
auth_info = self._ruleset_resolver.auth_schemes_to_signing_ctx(
File "/var/task/botocore/regions.py", line 711, in auth_schemes_to_signing_ctx
raise MissingDependencyException(
在本地,我已经设法通过这样做来解决这个问题
pip install awscrt
但是,当我使用新的依赖项创建新的 zip 时 - 我遇到了同样的错误。
我已经尝试将 botocore、awscrt、boto3 文件夹添加到包含所有依赖项的 zip 文件中,但它仍然不起作用。
经过长期调查,我们设法解决了这个问题。 创建客户端时,您应该添加配置签名版本 4。
例如:
在Python中:
from botocore.config import Config
my_config = Config(
signature_version='v4',
)
cloudfront_keyvaluestore_client = boto3.client('cloudfront-keyvaluestore', config=my_config, region_name='us-east-1')
在 NodeJS 中:
import '@aws-sdk/signature-v4-crt';
import { SignatureV4MultiRegion } from '@aws-sdk/signature-v4-multi-region';
const cloudFrontClient = new CloudFrontKeyValueStoreClient({
region: REGION,
signerConstructor: SignatureV4MultiRegion,
});
感谢您的帮助!