question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature Request: Glacier: upload_archive and get_job_output

See original GitHub issue

I am trying to mock simple Glacier calls (creation and deletion of a Glacier vault) and can’t find my way around this (despite being able to achieve such simple mocking with S3, creating a Bucket).

It seems that the mocking of Glacier simply isn’t taken into account.

Code is as follows:

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")

And I get the following exception at vault creation:

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"

I am using boto3 v1.17.49 and moto v2.0.8 that I installed using python3.7 -m pip install 'moto[all]'

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9

github_iconTop GitHub Comments

1reaction
bblommerscommented, Oct 8, 2021

Hi @EnzoMolion, happy to hear that Moto is useful for you! ‘get_job_output’ is implemented - there is a test for it here.

Thanks for letting me know about the implementation coverage doc - I’ll update that shortly 👍

1reaction
bblommerscommented, May 26, 2021

Hi @EnzoMolion, thanks for raising this!

having security token-related botocore exception

That’s definitely wrong. It looks like there’s a bug where we do not intercept the call when the vaultName has a . in it. It does work if you use a name without a .:

with mock_glacier():
    glacier_resource = boto3.resource('glacier', region_name="us-west-1")
    vault = glacier_resource.create_vault(accountId='-', vaultName="fakeglaciername")

I’ll update the title to reflect this.

With a working vaultName, moto will throw an error if you use an unknown region:

glacier_resource = boto3.client('glacier', region_name="fake-region-1")
vault = glacier_resource.create_vault(accountId='1234156789', vaultName="fakeglaciername")
    @classmethod
    def vault_response(clazz, request, full_url, headers):
        region_name = region_from_glacier_url(full_url)
>       response_instance = GlacierResponse(glacier_backends[region_name])
E       KeyError: 'fake-region-1'

../../moto/glacier/responses.py:34: KeyError
Read more comments on GitHub >

github_iconTop Results From Across the Web

Get Job Output (GET output) - Amazon S3 Glacier
Downloads the output of the job you initiated using the POST jobs operation. The output depends on the initial job type you specified....
Read more >
Glacier — Boto3 Docs 1.26.34 documentation - AWS
Contains the Amazon S3 Glacier response to your request. For information about the underlying REST API, see Upload Archive. For conceptual information, see ......
Read more >
Amazon S3 Glacier API Permissions: Actions, Resources, and ...
S3 Glacier API Operations Required Permissions (API Actions) Condition Keys Abort Vault Lock (DELETE lock‑policy) glacier:AbortVaultLock Complete Vault Lock (POST lockId) glacier:CompleteVaultLock glacier:Resourc... Create Vault (PUT...
Read more >
Glacier - LocalStack Docs
Glacier is a data storage service provided by Amazon Web Services to suit the long-term storage of archives and backup of infrequently ...
Read more >
AWS S3 Glacier Cheat Sheet (The Ultimate Backup Layer)
aws glacier upload-archive --acount-id - --vault-name my-glacier ... over 4 GB because it requires using a feature called multipart upload.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found