使用 moto 的基本 AWS Glacier 模拟失败

Failing basic AWS Glacier mocking using moto

我正在尝试模拟简单的 Glacier 调用(创建和删除 Glacier 保管库),但找不到解决方法(尽管能够使用 S3 实现这种简单的模拟,创建 Bucket)。

看来冰河的嘲讽根本就没有考虑进去

代码如下:

import boto3
from moto import mock_glacier

with mock_glacier():
    glacier_resource = boto3.resource('glacier', region_name="fake-glacier-region")
    vault = glacier_resource.create_vault(accountId='-', vaultName="fake.glacier.name")

我在创建保险库时遇到以下异常:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/<...>/test_mock_glacier.py", line 9, in test_simplest
    vault = glacier_resource.create_vault(accountId='-', vaultName="fake.glacier.name")
  File "/<...>/.local/lib/python3.7/site-packages/boto3/resources/factory.py", line 520, in do_action
    response = action(self, *args, **kwargs)
  File "/<...>/.local/lib/python3.7/site-packages/boto3/resources/action.py", line 83, in __call__
    response = getattr(parent.meta.client, operation_name)(*args, **params)
  File "/<...>/.local/lib/python3.7/site-packages/botocore/client.py", line 357, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/<...>/.local/lib/python3.7/site-packages/botocore/client.py", line 663, in _make_api_call
    operation_model, request_dict, request_context)
  File "/<...>/.local/lib/python3.7/site-packages/botocore/client.py", line 682, in _make_request
    return self._endpoint.make_request(operation_model, request_dict)
  File "/<...>/.local/lib/python3.7/site-packages/botocore/endpoint.py", line 102, in make_request
    return self._send_request(request_dict, operation_model)
  File "/<...>/.local/lib/python3.7/site-packages/botocore/endpoint.py", line 137, in _send_request
    success_response, exception):
  File "/<...>/.local/lib/python3.7/site-packages/botocore/endpoint.py", line 256, in _needs_retry
    caught_exception=caught_exception, request_dict=request_dict)
  File "/<...>/.local/lib/python3.7/site-packages/botocore/hooks.py", line 356, in emit
    return self._emitter.emit(aliased_event_name, **kwargs)
  File "/<...>/.local/lib/python3.7/site-packages/botocore/hooks.py", line 228, in emit
    return self._emit(event_name, kwargs)
  File "/<...>/.local/lib/python3.7/site-packages/botocore/hooks.py", line 211, in _emit
    response = handler(**kwargs)
  File "/<...>/.local/lib/python3.7/site-packages/botocore/retryhandler.py", line 183, in __call__
    if self._checker(attempts, response, caught_exception):
  File "/<...>/.local/lib/python3.7/site-packages/botocore/retryhandler.py", line 251, in __call__
    caught_exception)
  File "/<...>/.local/lib/python3.7/site-packages/botocore/retryhandler.py", line 277, in _should_retry
    return self._checker(attempt_number, response, caught_exception)
  File "/<...>/.local/lib/python3.7/site-packages/botocore/retryhandler.py", line 317, in __call__
    caught_exception)
  File "/<...>/.local/lib/python3.7/site-packages/botocore/retryhandler.py", line 223, in __call__
    attempt_number, caught_exception)
  File "/<...>/.local/lib/python3.7/site-packages/botocore/retryhandler.py", line 359, in _check_caught_exception
    raise caught_exception
  File "/<...>/.local/lib/python3.7/site-packages/botocore/endpoint.py", line 200, in _do_get_response
    http_response = self._send(request)
  File "/<...>/.local/lib/python3.7/site-packages/botocore/endpoint.py", line 269, in _send
    return self.http_session.send(request)
  File "/<...>/.local/lib/python3.7/site-packages/botocore/httpsession.py", line 343, in send
    raise EndpointConnectionError(endpoint_url=request.url, error=e)
botocore.exceptions.EndpointConnectionError: Could not connect to the endpoint URL: "https://glacier.fake-glacier-region.amazonaws.com/-/vaults/fake.glacier.name"

我正在使用我使用 python3.7 -m pip install 'moto[all]'

安装的 boto3 v1.17.49 和 moto v2.0.8

提供有效的 AWS 区域名称会导致以下异常:

botocore.exceptions.ClientError: An error occurred (UnrecognizedClientException) when calling the CreateVault operation: The security token included in the request is invalid.

(同时设置了 mock AWS_ACCESS_KEY_IDAWS_SECRET_ACCESS_KEYAWS_SECURITY_TOKENAWS_SESSION_TOKEN 环境变量(以 'testing' 作为值),如 moto 的自述文件中所述)

I turned out to be a bug,其中 Glacier 保管库的名称中不能包含 .

A fix正在开发中(合并到master,将与2.0.9版本一起发布)

Quickfix 因此将 vaultName="fake.glacier.name" 更改为 vaultName="fakeGlacierName"