runMicrovm method

Future<RunMicrovmResponse> runMicrovm({
  1. required String imageIdentifier,
  2. String? clientToken,
  3. List<String>? egressNetworkConnectors,
  4. String? executionRoleArn,
  5. IdlePolicy? idlePolicy,
  6. String? imageVersion,
  7. List<String>? ingressNetworkConnectors,
  8. Logging? logging,
  9. int? maximumDurationInSeconds,
  10. String? runHookPayload,
})

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.

May throw AccessDeniedException. May throw ConflictException. May throw InternalServerException. May throw ResourceNotFoundException. May throw ServiceQuotaExceededException. May throw ThrottlingException. May throw ValidationException.

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

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

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

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

Parameter idlePolicy : Configuration to control auto-suspend and auto-resume behavior.

Parameter imageVersion : The version of the MicroVM image to run.

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

Parameter logging : 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.

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

Parameter runHookPayload : 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.

Implementation

Future<RunMicrovmResponse> runMicrovm({
  required String imageIdentifier,
  String? clientToken,
  List<String>? egressNetworkConnectors,
  String? executionRoleArn,
  IdlePolicy? idlePolicy,
  String? imageVersion,
  List<String>? ingressNetworkConnectors,
  Logging? logging,
  int? maximumDurationInSeconds,
  String? runHookPayload,
}) async {
  final $payload = <String, dynamic>{
    'imageIdentifier': imageIdentifier,
    'clientToken': clientToken ?? _s.generateIdempotencyToken(),
    if (egressNetworkConnectors != null)
      'egressNetworkConnectors': egressNetworkConnectors,
    if (executionRoleArn != null) 'executionRoleArn': executionRoleArn,
    if (idlePolicy != null) 'idlePolicy': idlePolicy,
    if (imageVersion != null) 'imageVersion': imageVersion,
    if (ingressNetworkConnectors != null)
      'ingressNetworkConnectors': ingressNetworkConnectors,
    if (logging != null) 'logging': logging,
    if (maximumDurationInSeconds != null)
      'maximumDurationInSeconds': maximumDurationInSeconds,
    if (runHookPayload != null) 'runHookPayload': runHookPayload,
  };
  final response = await _protocol.send(
    payload: $payload,
    method: 'POST',
    requestUri: '/2025-09-09/microvms',
    exceptionFnMap: _exceptionFns,
  );
  return RunMicrovmResponse.fromJson(response);
}