amis icon indicating copy to clipboard operation
amis copied to clipboard

Script fails during `Importing s3://[...] to EC2` due to hitting timeout early

Open clushie opened this issue 9 months ago • 3 comments

I'm uploading an 8GB image, that fails because I'm hitting a timeout inside AWS itself I believe.

INFO:root:Importing s3://[...] to EC2
Traceback (most recent call last):
  File "/nix/store/4mfrfrzjlj8garawxwlmam3wk7z3b0jq-upload-ami-0.1.0/bin/.upload-ami-wrapped", line 9, in <module>
    sys.exit(main())
             ^^^^^^
  File "/nix/store/4mfrfrzjlj8garawxwlmam3wk7z3b0jq-upload-ami-0.1.0/lib/python3.12/site-packages/upload_ami/upload_ami.py", line 364, in main
    image_ids = upload_ami(
                ^^^^^^^^^^^
  File "/nix/store/4mfrfrzjlj8garawxwlmam3wk7z3b0jq-upload-ami-0.1.0/lib/python3.12/site-packages/upload_ami/upload_ami.py", line 317, in upload_ami
    snapshot_id = import_snapshot_if_not_exist(
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/4mfrfrzjlj8garawxwlmam3wk7z3b0jq-upload-ami-0.1.0/lib/python3.12/site-packages/upload_ami/upload_ami.py", line 97, in import_snapshot_if_not_exist
    ec2.get_waiter("snapshot_imported").wait(
  File "/nix/store/04n4qsdzamhy6q23wdc7xzwggd7ggpxl-python3.12-botocore-1.35.30/lib/python3.12/site-packages/botocore/waiter.py", line 55, in wait
    Waiter.wait(self, **kwargs)
  File "/nix/store/04n4qsdzamhy6q23wdc7xzwggd7ggpxl-python3.12-botocore-1.35.30/lib/python3.12/site-packages/botocore/waiter.py", line 387, in wait
    raise WaiterError(
botocore.exceptions.WaiterError: Waiter SnapshotImported failed: Max attempts exceeded

Running a bit later aws ec2 describe-import-snapshot-tasks I can see that the import was successful and it shows up as an Snapshot in the AWS EC2 Snpashot UI and when running aws ec2 describe-snapshots --max-results 5.

clushie avatar Apr 17 '25 16:04 clushie

We could expose flags to override the default waiter timeouts.

arianvp avatar Apr 17 '25 17:04 arianvp

That would be great, however I believe the current timeout might be a bit too low? 8GB AMI is I believe a reasonable size.

I just ran into this here https://github.com/numtide/terraform-upload-ami/blob/main/main.tf so seems there is also a completely terraform/tofu native way to upload AMIs, maybe I'll give this a try next.

:) Anyway, thanks for your work so far - helped quite a bit ✨ !

clushie avatar Apr 17 '25 17:04 clushie

That would be great, however I believe the current timeout might be a bit too low?

Amazon teams come up with these timeouts. If the default is too low that's an upstream bug in their SDK that we should file I think. As you noticed these default timeouts are also used by terraform.

But we can bump them here for now as a workaround. You wanna open a PR for that?

arianvp avatar Apr 18 '25 10:04 arianvp