Skip to content

disable_image

disable_image(
    *,
    config_overrides: Optional[EC2ClientConfig] = None,
    image_id: Optional[ImageId] = None,
    dry_run: Optional[Boolean] = None,
) -> DisableImageResult

Sets the AMI state to disabled and removes all launch permissions from the AMI. A disabled AMI can't be used for instance launches.

A disabled AMI can't be shared. If an AMI was public or previously shared, it is made private. If an AMI was shared with an Amazon Web Services account, organization, or Organizational Unit, they lose access to the disabled AMI.

A disabled AMI does not appear in DescribeImages API calls by default.

Only the AMI owner can disable an AMI.

You can re-enable a disabled AMI using EnableImage.

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

Parameters:

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

    The ID of the AMI.

  • 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 disable_image(
    self,
    *,
    config_overrides: Optional[EC2ClientConfig] = None,
    image_id: Optional["capo_ec2.types.image_id.ImageId"] = None,
    dry_run: Optional["capo_ec2.types.boolean.Boolean"] = None,
) -> "capo_ec2.types.disable_image_result.DisableImageResult":
    """<p>Sets the AMI state to <code>disabled</code> and removes all launch permissions from the AMI. A disabled AMI can't be used for instance launches.</p> <p>A disabled AMI can't be shared. If an AMI was public or previously shared, it is made private. If an AMI was shared with an Amazon Web Services account, organization, or Organizational Unit, they lose access to the disabled AMI. </p> <p>A disabled AMI does not appear in <a href="https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeImages.html">DescribeImages</a> API calls by default.</p> <p>Only the AMI owner can disable an AMI.</p> <p>You can re-enable a disabled AMI using <a href="https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_EnableImage.html">EnableImage</a>.</p> <p>For more information, see <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/disable-an-ami.html">Disable an AMI</a> in the <i>Amazon EC2 User Guide</i>.</p>

    Args:
        image_id: <p>The ID of the AMI.</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.disable_image_request.DisableImageRequest]",
    ) -> OperationResponse[
        "capo_ec2.types.disable_image_result.DisableImageResult"
    ]:
        import capo_ec2._operations.amazon_ec2.disable_image

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

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("DisableImage")
    )
    input_: capo_ec2.types.disable_image_request.DisableImageRequest = {}
    if image_id is not None:
        input_["image_id"] = image_id
    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