Skip to content

deregister_image

deregister_image(
    *,
    config_overrides: Optional[EC2ClientConfig] = None,
    image_id: Optional[ImageId] = None,
    delete_associated_snapshots: Optional[Boolean] = None,
    dry_run: Optional[Boolean] = None,
) -> DeregisterImageResult

Deregisters the specified AMI. A deregistered AMI can't be used to launch new instances.

If a deregistered EBS-backed AMI matches a Recycle Bin retention rule, it moves to the Recycle Bin for the specified retention period. It can be restored before its retention period expires, after which it is permanently deleted. If the deregistered AMI doesn't match a retention rule, it is permanently deleted immediately. For more information, see Recover deleted Amazon EBS snapshots and EBS-backed AMIs with Recycle Bin in the Amazon EBS User Guide.

When deregistering an EBS-backed AMI, you can optionally delete its associated snapshots at the same time. However, if a snapshot is associated with multiple AMIs, it won't be deleted even if specified for deletion, although the AMI will still be deregistered.

Deregistering an AMI does not delete the following:

  • Instances already launched from the AMI. You'll continue to incur usage costs for the instances until you terminate them.

  • For EBS-backed AMIs: Snapshots that are associated with multiple AMIs. You'll continue to incur snapshot storage costs.

  • For instance store-backed AMIs: The files uploaded to Amazon S3 during AMI creation. You'll continue to incur S3 storage costs.

For more information, see Deregister an Amazon EC2 AMI in the Amazon EC2 User Guide.

Parameters:

  • image_id (Optional[ImageId], default: None ) –

    The ID of the AMI.

  • delete_associated_snapshots (Optional[Boolean], default: None ) –

    Specifies whether to delete the snapshots associated with the AMI during deregistration.

    If a snapshot is associated with multiple AMIs, it is not deleted, regardless of this setting.

    Default: The snapshots are not deleted.

  • dry_run (Optional[Boolean], default: None ) –

    Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions, the error response is DryRunOperation. Otherwise, it is UnauthorizedOperation.

Raises:

Source code in docs_src/capo_ec2/_services/ec2.py
def deregister_image(
    self,
    *,
    config_overrides: Optional[EC2ClientConfig] = None,
    image_id: Optional["capo_ec2.types.image_id.ImageId"] = None,
    delete_associated_snapshots: Optional["capo_ec2.types.boolean.Boolean"] = None,
    dry_run: Optional["capo_ec2.types.boolean.Boolean"] = None,
) -> "capo_ec2.types.deregister_image_result.DeregisterImageResult":
    """<p>Deregisters the specified AMI. A deregistered AMI can't be used to launch new instances.</p> <p>If a deregistered EBS-backed AMI matches a Recycle Bin retention rule, it moves to the Recycle Bin for the specified retention period. It can be restored before its retention period expires, after which it is permanently deleted. If the deregistered AMI doesn't match a retention rule, it is permanently deleted immediately. For more information, see <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/recycle-bin.html">Recover deleted Amazon EBS snapshots and EBS-backed AMIs with Recycle Bin</a> in the <i>Amazon EBS User Guide</i>.</p> <p>When deregistering an EBS-backed AMI, you can optionally delete its associated snapshots at the same time. However, if a snapshot is associated with multiple AMIs, it won't be deleted even if specified for deletion, although the AMI will still be deregistered.</p> <p>Deregistering an AMI does not delete the following:</p> <ul> <li> <p>Instances already launched from the AMI. You'll continue to incur usage costs for the instances until you terminate them.</p> </li> <li> <p>For EBS-backed AMIs: Snapshots that are associated with multiple AMIs. You'll continue to incur snapshot storage costs.</p> </li> <li> <p>For instance store-backed AMIs: The files uploaded to Amazon S3 during AMI creation. You'll continue to incur S3 storage costs.</p> </li> </ul> <p>For more information, see <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/deregister-ami.html">Deregister an Amazon EC2 AMI</a> in the <i>Amazon EC2 User Guide</i>.</p>

    Args:
        image_id: <p>The ID of the AMI.</p>
        delete_associated_snapshots: <p>Specifies whether to delete the snapshots associated with the AMI during deregistration.</p> <note> <p>If a snapshot is associated with multiple AMIs, it is not deleted, regardless of this setting.</p> </note> <p>Default: The snapshots are not deleted.</p>
        dry_run: <p>Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions, the error response is <code>DryRunOperation</code>. Otherwise, it is <code>UnauthorizedOperation</code>.</p>

    Raises:
        capo_ec2.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    def _handler(
        req: "OperationRequest[capo_ec2.types.deregister_image_request.DeregisterImageRequest]",
    ) -> OperationResponse[
        "capo_ec2.types.deregister_image_result.DeregisterImageResult"
    ]:
        import capo_ec2._operations.amazon_ec2.deregister_image

        output, http_response = (
            capo_ec2._operations.amazon_ec2.deregister_image.deregister_image(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("DeregisterImage")
    )
    input_: capo_ec2.types.deregister_image_request.DeregisterImageRequest = {}
    if image_id is not None:
        input_["image_id"] = image_id
    if delete_associated_snapshots is not None:
        input_["delete_associated_snapshots"] = delete_associated_snapshots
    if dry_run is not None:
        input_["dry_run"] = dry_run

    response = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    response.response.close()
    return response.output