Skip to content

run_microvm

run_microvm(
    image_identifier: MicrovmImageIdentifier,
    *,
    config_overrides: Optional[LambdaMicrovmsClientConfig] = None,
    ingress_network_connectors: Optional[NetworkConnectorList] = None,
    egress_network_connectors: Optional[NetworkConnectorList] = None,
    image_version: Optional[Version] = None,
    execution_role_arn: Optional[RoleArn] = None,
    idle_policy: Optional[IdlePolicy] = None,
    logging: Optional[Logging] = None,
    run_hook_payload: Optional[RunHookPayload] = None,
    maximum_duration_in_seconds: Optional[int] = None,
    client_token: Optional[str] = None,
) -> RunMicrovmResponse

Runs a new MicroVM from the specified image. The MicroVM starts in PENDING state and transitions to RUNNING once provisioning completes. To connect, generate an authentication token using CreateMicrovmAuthToken.

Parameters:

  • ingress_network_connectors (Optional[NetworkConnectorList], default: None ) –

    The list of ingress network connectors to configure for the MicroVM.

  • egress_network_connectors (Optional[NetworkConnectorList], default: None ) –

    The list of egress network connectors to configure for the MicroVM.

  • image_identifier (MicrovmImageIdentifier) –

    The identifier (ARN or ID) of the MicroVM image to run.

  • image_version (Optional[Version], default: None ) –

    The version of the MicroVM image to run.

  • execution_role_arn (Optional[RoleArn], default: None ) –

    The ARN of the IAM role to be assumed by the MicroVM during execution.

  • idle_policy (Optional[IdlePolicy], default: None ) –

    Configuration to control auto-suspend and auto-resume behavior.

  • logging (Optional[Logging], default: None ) –

    The logging configuration for this MicroVM instance. Specify {"cloudWatch": {"logGroup": "..."}} to stream application logs to a custom CloudWatch log group, or {"disabled": {}} to turn off logging.

  • run_hook_payload (Optional[RunHookPayload], default: None ) –

    Per-MicroVM initialization data delivered as the request body of the /run lifecycle hook. Use to pass tenant-specific configuration such as session IDs or secret references. Maximum: 16,384 bytes.

  • maximum_duration_in_seconds (Optional[int], default: None ) –

    The maximum duration in seconds that the MicroVM can exist before being terminated by the platform. Valid range: 1–28,800 (8 hours).

  • client_token (Optional[str], default: None ) –

    A unique, case-sensitive identifier you provide to ensure the idempotency of the request.

Raises:

Source code in docs_src/capo_lambda_microvms/_services/lambda_microvms.py
def run_microvm(
    self,
    image_identifier: "capo_lambda_microvms.types.microvm_image_identifier.MicrovmImageIdentifier",
    *,
    config_overrides: Optional[LambdaMicrovmsClientConfig] = None,
    ingress_network_connectors: Optional[
        "capo_lambda_microvms.types.network_connector_list.NetworkConnectorList"
    ] = None,
    egress_network_connectors: Optional[
        "capo_lambda_microvms.types.network_connector_list.NetworkConnectorList"
    ] = None,
    image_version: Optional["capo_lambda_microvms.types.version.Version"] = None,
    execution_role_arn: Optional[
        "capo_lambda_microvms.types.role_arn.RoleArn"
    ] = None,
    idle_policy: Optional[
        "capo_lambda_microvms.types.idle_policy.IdlePolicy"
    ] = None,
    logging: Optional["capo_lambda_microvms.types.logging.Logging"] = None,
    run_hook_payload: Optional[
        "capo_lambda_microvms.types.run_hook_payload.RunHookPayload"
    ] = None,
    maximum_duration_in_seconds: Optional[int] = None,
    client_token: Optional[str] = None,
) -> "capo_lambda_microvms.types.run_microvm_response.RunMicrovmResponse":
    """<p>Runs a new MicroVM from the specified image. The MicroVM starts in PENDING state and transitions to RUNNING once provisioning completes. To connect, generate an authentication token using CreateMicrovmAuthToken.</p>

    Args:
        ingress_network_connectors: <p>The list of ingress network connectors to configure for the MicroVM.</p>
        egress_network_connectors: <p>The list of egress network connectors to configure for the MicroVM.</p>
        image_identifier: <p>The identifier (ARN or ID) of the MicroVM image to run.</p>
        image_version: <p>The version of the MicroVM image to run.</p>
        execution_role_arn: <p>The ARN of the IAM role to be assumed by the MicroVM during execution.</p>
        idle_policy: <p>Configuration to control auto-suspend and auto-resume behavior.</p>
        logging: <p>The logging configuration for this MicroVM instance. Specify {"cloudWatch": {"logGroup": "..."}} to stream application logs to a custom CloudWatch log group, or {"disabled": {}} to turn off logging.</p>
        run_hook_payload: <p>Per-MicroVM initialization data delivered as the request body of the /run lifecycle hook. Use to pass tenant-specific configuration such as session IDs or secret references. Maximum: 16,384 bytes.</p>
        maximum_duration_in_seconds: <p>The maximum duration in seconds that the MicroVM can exist before being terminated by the platform. Valid range: 1–28,800 (8 hours).</p>
        client_token: <p>A unique, case-sensitive identifier you provide to ensure the idempotency of the request.</p>

    Raises:
        capo_lambda_microvms.errors.access_denied_exception.AccessDeniedException: <p>You do not have sufficient access to perform this action.</p>
        capo_lambda_microvms.errors.internal_server_exception.InternalServerException: <p>An internal server error occurred. Retry the request later.</p>
        capo_lambda_microvms.errors.throttling_exception.ThrottlingException: <p>The request was denied due to request throttling. Retry the request later.</p>
        capo_lambda_microvms.errors.validation_exception.ValidationException: <p>The input does not satisfy the constraints specified by the service.</p>
        capo_lambda_microvms.errors.conflict_exception.ConflictException: <p>The request could not be completed due to a conflict with the current state of the resource.</p>
        capo_lambda_microvms.errors.insufficient_capacity_exception.InsufficientCapacityException: <p>There is insufficient capacity to fulfill the request. Retry the request later.</p>
        capo_lambda_microvms.errors.resource_not_found_exception.ResourceNotFoundException: <p>The specified resource does not exist.</p>
        capo_lambda_microvms.errors.service_quota_exceeded_exception.ServiceQuotaExceededException: <p>You have exceeded a service quota for Lambda MicroVMs.</p>
        capo_lambda_microvms.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    def _handler(
        req: "OperationRequest[capo_lambda_microvms.types.run_microvm_request.RunMicrovmRequest]",
    ) -> OperationResponse[
        "capo_lambda_microvms.types.run_microvm_response.RunMicrovmResponse"
    ]:
        import capo_lambda_microvms._operations.lambda_microvms.run_microvm

        output, http_response = (
            capo_lambda_microvms._operations.lambda_microvms.run_microvm.run_microvm(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    def _redact_input(
        input_: "capo_lambda_microvms.types.run_microvm_request.RunMicrovmRequest",
    ) -> dict[str, Any]:
        import capo_lambda_microvms.types.run_microvm_request

        return capo_lambda_microvms.types.run_microvm_request.redact_sensitive(
            input_
        )

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("RunMicrovm", redact_input=_redact_input)
    )
    input_: capo_lambda_microvms.types.run_microvm_request.RunMicrovmRequest = {
        "image_identifier": image_identifier
    }
    if ingress_network_connectors is not None:
        input_["ingress_network_connectors"] = ingress_network_connectors
    if egress_network_connectors is not None:
        input_["egress_network_connectors"] = egress_network_connectors
    if image_version is not None:
        input_["image_version"] = image_version
    if execution_role_arn is not None:
        input_["execution_role_arn"] = execution_role_arn
    if idle_policy is not None:
        input_["idle_policy"] = idle_policy
    if logging is not None:
        input_["logging"] = logging
    if run_hook_payload is not None:
        input_["run_hook_payload"] = run_hook_payload
    if maximum_duration_in_seconds is not None:
        input_["maximum_duration_in_seconds"] = maximum_duration_in_seconds
    if client_token is None:
        client_token = str(uuid.uuid4())
    input_["client_token"] = client_token

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