boto / boto3

AWS SDK for Python
https://aws.amazon.com/sdk-for-python/
Apache License 2.0
9.06k stars 1.87k forks source link

Not able to copy tags using copy_image #3750

Closed ayushtessell closed 1 year ago

ayushtessell commented 1 year ago

Describe the bug

when using copy_image method

       object = s3_client.copy_image(
            Description="This is copied snapshot from SourceAmi {0} region {1}".format(
                self.ami_id, self.origin_region
            ),
            Name="Copied from {0} region {1}".format(self.ami_id, self.origin_region),
            SourceRegion=self.origin_region,
            SourceImageId=self.ami_id,
            CopyImageTags=True,
        )

it gives error Unknown parameter in input: "CopyImageTags", must be one of: ClientToken, Description, Encrypted, KmsKeyId, Name, SourceImageId, SourceRegion, DestinationOutpostArn, DryRun

Expected Behavior

All user defined tags from source should be copied to destination ami when CopyImageTags=True

Current Behavior

Gives out error when giving CopyImageTags parameter

  File "/Users/ayushman/Documents/github_projects/github_upload_tessell/tessell-packer-framework/scripts/aws_process.py", line 139, in copy_aws_ami
    object = s3_client.copy_image(
  File "/Users/ayushman/Documents/github_projects/github_upload_tessell/wheel_python1/lib/python3.9/site-packages/botocore/client.py", line 514, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/Users/ayushman/Documents/github_projects/github_upload_tessell/wheel_python1/lib/python3.9/site-packages/botocore/client.py", line 901, in _make_api_call
    request_dict = self._convert_to_request_dict(
  File "/Users/ayushman/Documents/github_projects/github_upload_tessell/wheel_python1/lib/python3.9/site-packages/botocore/client.py", line 962, in _convert_to_request_dict
    request_dict = self._serializer.serialize_to_request(
  File "/Users/ayushman/Documents/github_projects/github_upload_tessell/wheel_python1/lib/python3.9/site-packages/botocore/validate.py", line 381, in serialize_to_request
    raise ParamValidationError(report=report.generate_report())
botocore.exceptions.ParamValidationError: Parameter validation failed:
Unknown parameter in input: "CopyImageTags", must be one of: ClientToken, Description, Encrypted, KmsKeyId, Name, SourceImageId, SourceRegion, DestinationOutpostArn, DryRun

Reproduction Steps

    s3_client = boto3.client(
        "ec2",
        region_name=copy_region,
        aws_access_key_id=aws_access_key,
        aws_secret_access_key=aws_secret_key,
    )
    object = s3_client.copy_image(
        Description="This is copied snapshot from SourceAmi {0} region {1}".format(
            self.ami_id, self.origin_region
        ),
        Name="Copied from {0} region {1}".format(self.ami_id, self.origin_region),
        SourceRegion=self.origin_region,
        SourceImageId=self.ami_id,
    )

Possible Solution

No response

Additional Information/Context

No response

SDK version used

boto3: 1.24.71

Environment details (OS name and version, etc.)

python3, macos

tim-finnigan commented 1 year ago

Hi @ayushtessell thanks for reaching out. Can you update your version of boto3 and try running this again? The latest version is 1.26.152 per the CHANGELOG, and it looks like support for CopyImageTags was released in 1.26.13. I'll also share the EC2 copy_image client method documentation for reference.

ayushtessell commented 1 year ago

Thank-you so much @tim-finnigan ,

also I wanted to know can a similar feature be added to copy_snapshot method (like CopySnapshotTags=True). Right now we have to use TagSpecifications (where we have give input of tags in key-value pair) which I think is similar to create_tags

tim-finnigan commented 1 year ago

Hi @ayushtessell thanks for following up. That request would need to go to the EC2 team, as they own the underlying CopySnapshot API. If you have a support plan we recommend reaching out through AWS support for requests like these. Or we can also forward this feature request to the service team. Please let us know.

ayushtessell commented 1 year ago

Currently I have created a workaround to do my work, but it would be beneficial if this feature is added. And currently I don't have a plan to implement this feature

tim-finnigan commented 1 year ago

Thanks for following up. I have reached out to the EC2 team for consideration of this use case. I also created an issue for this here in our cross-SDK repository since service APIs are used across SDKs: https://github.com/aws/aws-sdk/issues/553. Please refer to that issue for updates going forward, and if you have any more information to share regarding your use case please leave a comment on that issue.