Skip to main content

Machines

You can use the Machines resource to create, stop, start, update, and delete Fly Machines. Fly Machines are fast-launching VMs on Fly.io. The Machine resource is the configuration and state for a Machine.

Machine properties

List Machines

GET /v1/apps/{app_name}/machines List all the Machines for an app.

Path parameters

string
required
The name of the Fly App to list Machines for.

Query parameters

Boolean
If true, include deleted Machines in the response.
String
Filter by region. For example, to return only Machines in the yyz region: GET /v1/apps/my-app-name/machines?region=yyz
String
Filter by metadata key-value pair. For example, to return only Machines with metadata item "foo": "bar" : GET /v1/apps/my-app-name/machines?metadata.foo=bar
GET/v1/apps/{app_name}/machines
Status: 200 OK - Example response

Create a Machine

POST /v1/apps/{app_name}/machines Given the name of a Fly App, create a Fly Machine, given the URI of a container image, in some region (or, by default, the region closest to you) on Fly.io’s platform. If successful, that Machine will boot up by default. Create a Machine without booting it by setting skip_launch. You can configure the Machine characteristics, like its CPU and memory. You can also allow connections from the internet through the Fly Proxy by creating a Machine with services. Learn more about this behavior in the networking section.
Important: This request can fail, and you’re responsible for handling that failure. If you ask for a large Machine, or a Machine in a region we happen to be at capacity for, you might need to retry the request, or to fall back to another region. If you’re working directly with the Machines API, you’re taking some responsibility for your own orchestration!
The only required parameter in the body is image in the config object.

Path parameters

string
required
The name of the Fly App to create a Machine for.

Body parameters

string
Unique name for this Machine. If omitted, one is generated for you. String.
string
The target region. Omitting this param launches in the same region as your WireGuard peer connection (somewhere near you). String.
integer
Acquire a lease on the newly created Machine, waiting this many seconds before failing the request; use to create a Machine that can’t be updated by any other external process while waiting for it to come up and pass health checks.
boolean
Create a Fly Machine, but don’t boot it up, leaving it in a state where it can be quickly started in response to events. Think of this as “warming the caches” on our hardware. (default: false)
boolean
Enable Log Structured Virtual Disks for this Machine. (default: false)
boolean
Leave this Machine disconnected from Fly.io’s request routing. This is like a combined Create and Cordon operation; register the Machine later with an Uncordon request. Useful for bluegreen deploys: bring a Machine up, test it healthy, and only then let user requests hit it. (default: false)
object
required
Required for image. An object defining the Machine configuration. See the config object properties section.
POST/v1/apps/{app_name}/machines
Status: 200 OK - Example response

Create a Machine with services

POST /v1/apps/{app_name}/machines Create a Machine with services defined on app. Learn more about services and networking.

Path parameters

string
required
The name of the Fly App to create a Machine for.

Body parameters

string
Unique name for this Machine. If omitted, one is generated for you. String.
string
The target region. Omitting this param launches in the same region as your WireGuard peer connection (somewhere near you). String.
integer
Acquire a lease on the newly created Machine, waiting this many seconds before failing the request; use to create a Machine that can’t be updated by any other external process while waiting for it to come up and pass health checks.
boolean
Create a Fly Machine, but don’t boot it up, leaving it in a state where it can be quickly started in response to events. Think of this as “warming the caches” on our hardware. (default: false)
boolean
Enable Log Structured Virtual Disks for this Machine. (default: false)
boolean
Leave this Machine disconnected from Fly.io’s request routing. This is like a combined Create and Cordon operation; register the Machine later with an Uncordon request. Useful for bluegreen deploys: bring a Machine up, test it healthy, and only then let user requests hit it. (default: false)
object
required
Required for image. An object defining the Machine configuration. See the config object properties section.
POST/v1/apps/{app_name}/machines
Status: 200 OK - Example response

Wait for a Machine to reach a specified state

GET /v1/apps/{app_name}/machines/{machine_id}/wait

Path parameters

string
required
The name of the Fly App the Machine belongs to.
string
required
The ID of the Machine to wait for.

Query parameters

string
Filter for a specific Machine instance_id (version). Required when waiting for Machine to be in stopped state.
integer
The time, in seconds, to wait for the Machine to enter the specified state. Default is 60.
string enum
The Machine state to wait for. Values are: started, stopped, suspended, or destroyed. Default is started.
GET/v1/apps/{app_name}/machines/{machine_id}/wait
Status: 200 OK - Example response

Get a Machine

GET /v1/apps/{app_name}/machines/{machine_id} Given the name of a Fly App and a Fly Machine ID, retrieve the details of that Machine.

Path parameters

string
required
The name of the Fly App the Machine belongs to.
string
required
The ID of the Machine to get.
GET/v1/apps/{app_name}/machines/{machine_id}
Status: 200 OK - Example response

Update a Machine

POST /v1/apps/{app_name}/machines/{machine_id} Given the name of a Fly App and a Fly Machine ID, update the configuration of the Machine. If the Machine is running and the request is successful, it will reboot; if the Machine isn’t running, and you don’t want it to start up, set skip_launch. This is, in particular, how you would update the running image of a Machine (when you need to deploy new code), or roll back to a previous Machine release. It’s also how you’d vertically scale an application.
Important: This request can fail, and you’re responsible for handling that failure. If you ask for a large Machine, or a Machine in a region we happen to be at capacity for, you might need to retry the request, or to fall back to another region. If you’re working directly with the Machines API, you’re taking some responsibility for your own orchestration!
region and name are immutable and cannot be updated.
Note: You need to specify the entire Machine config to update a Machine; we don’t support partial updates. You can get the Machine you want to update, copy and modify the config and include it in the body of the update request. Refer to the Machine config object properties section for property descriptions.

Request headers

string
The Machine lease nonce, a random value we provide that indicates that you currently hold the lease on this Machine. If the Machine is leased, and you don’t provide this header, the request to update the Machine will fail.

Path parameters

string
required
The name of the Fly App the Machine belongs to.
string
required
The ID of the Machine to update.

Body parameters

object
required
An object defining the Machine configuration. See the config object properties section.
string
The latest instance_id value of the Machine.
string
Unique name for this Machine. If omitted, one is generated for you. String.
string
The target region. Omitting this param launches in the same region as your WireGuard peer connection (somewhere near you). String.
integer
Acquire a lease on the newly created Machine, waiting this many seconds before failing the request; use to create a Machine that can’t be updated by any other external process while waiting for it to come up and pass health checks.
boolean
Create a Fly Machine, but don’t boot it up, leaving it in a state where it can be quickly started in response to events. Think of this as “warming the caches” on our hardware. (default: false)
boolean
Enable Log Structured Virtual Disks for this Machine. (default: false)
boolean
Leave this Machine disconnected from Fly.io’s request routing. This is like a combined Create and Cordon operation; register the Machine later with an Uncordon request. Useful for bluegreen deploys: bring a Machine up, test it healthy, and only then let user requests hit it. (default: false)
POST/v1/apps/{app_name}/machines/{machine_id}
Status: 200 OK - Example response

Stop a Machine

POST /v1/apps/{app_name}/machines/{machine_id}/stop Stopping a started Machine will shut down the Machine, but not destroy it. The Machine can be started again with machines/<machine_id>/start. Stopping a suspended Machine will invalidate its snapshot, forcing it to perform a cold boot the next time it is started.

Path parameters

string
required
The name of the Fly App the Machine belongs to.
string
required
The ID of the Machine to stop.

Body parameters

object
Signal to stop the Machine with. (default: SIGINT)
string
Seconds to wait before sending SIGKILL to the Machine
POST/v1/apps/{app_name}/machines/{machine_id}/stop
Status: 200 OK - Example response

Suspend a Machine

POST /v1/apps/{app_name}/machines/{machine_id}/suspend Suspending a Machine pauses the Machine and takes a snapshot of its state, including its memory. The next start operation will attempt (but is not guaranteed) to resume the Machine from the snapshot, rather than performing a cold boot.

Path parameters

string
required
The name of the Fly App the Machine belongs to.
string
required
The ID of the Machine to suspend.
POST/v1/apps/{app_name}/machines/{machine_id}/suspend
Status: 200 OK - Example response

Start a Machine

POST /v1/apps/{app_name}/machines/{machine_id}/start Start a Machine. Stopped Machines that are restarted are completely reset to their original state so that they start clean on the next run. Suspended Machines that are started attempt to resume from the snapshot taken when they were suspended. If this is not possible, then they will perform a cold boot, as though starting from the stopped state; however, their root file systems will not be reset.

Path parameters

string
required
The name of the Fly App the Machine belongs to.
string
required
The ID of the Machine to start.
POST/v1/apps/{app_name}/machines/{machine_id}/start
Status: 200 OK - Example response

Delete a Machine permanently

DELETE /v1/apps/{app_name}/machines/{machine_id} Delete a Machine. This action cannot be undone. Given the name of a Fly App and the Machine ID of a Fly Machine, delete the Machine.

Path parameters

string
required
The name of the Fly App the Machine belongs to.
string
required
The ID of the Machine to delete.

Query parameters

boolean
Force stop the Machine if running.
DELETE/v1/apps/{app_name}/machines/{machine_id}
Status: 200 OK - Example response

Create a Machine lease

POST /v1/apps/{app_name}/machines/{machine_id}/lease Create a lease for a specific Machine within an app using the details provided in the request body. Machine leases can be used to obtain an exclusive lock on modifying a Machine. The Machine lease nonce is a random value we provide that indicates that you currently hold the lease on a Machine. To use the provided nonce from the create or get lease response, add the fly-machine-lease-nonce header to all subsequent API calls to the Machine for the duration of the lease. See Release a Machine lease.

Path parameters

string
required
The name of the Fly App the Machine belongs to.
string
required
The ID of the Machine to create a lease for.

Body parameters

string
A description of the lease for convenience.
integer
The time in seconds that the lease should be held for.
POST/v1/apps/{app_name}/machines/{machine_id}/lease
Status: 201 created - Example response

Get a Machine lease

GET /v1/apps/{app_name}/machines/{machine_id}/lease Retrieve the current lease of a specific Machine within an app. Machine leases can be used to obtain an exclusive lock on modifying a Machine.

Path parameters

string
required
The name of the Fly App the Machine belongs to.
string
required
The ID of the Machine to retrieve a lease for.
GET/v1/apps/{app_name}/machines/{machine_id}/lease
Status: 200 OK - Example response

Release a Machine lease

DELETE /v1/apps/{app_name}/machines/{machine_id}/lease Release the lease of a specific Machine within an app. Machine leases can be used to obtain an exclusive lock on modifying a Machine.

Request headers

string
Required to release a lease. The Machine lease nonce, a random value provided in the response when you get or create a lease.

Path parameters

string
required
The name of the Fly App the Machine belongs to.
string
required
The ID of the Machine to release a lease for.
DELETE/v1/apps/{app_name}/machines/{machine_id}/lease
Status: 200 OK - Example response

Route requests away from or back to a Machine

POST /v1/apps/{app_name}/machines/{machine_id}/cordon POST /v1/apps/{app_name}/machines/{machine_id}/uncordon Given the name of a Fly App and the Machine ID of a Fly Machine, instruct the Fly Proxy not to send requests to a Machine or to start sending requests again to a previously cordoned Machine. You can also do this with a fresh Machine, all in one shot, using the skip_service_registration request field of a Machine Create request. This is useful for bluegreen deployments: boot up a new, “green”, cordoned Machine running the new release (using skip_service_registration), make sure it’s healthy, then uncordon it and tear down the old, “blue” Machine.

Path parameters

string
required
The name of the Fly App the Machine belongs to.
string
required
The ID of the Machine to cordon or uncordon.
POST/v1/apps/{app_name}/machines/{machine_id}/cordon
POST/v1/apps/{app_name}/machines/{machine_id}/uncordon
Status: 200 OK - Example response

Get a Machine’s metadata

GET /v1/apps/{app_name}/machines/{machine_id}/metadata Get the metadata defined in a specific Machine’s config.

Path parameters

string
required
The name of the Fly App the Machine belongs to.
string
required
The ID of the Machine to get the metadata for.
GET/v1/apps/{app_name}/machines/{machine_id}/metadata
Status: 200 OK - Example response

Add or update Machine metadata

POST /v1/apps/{app_name}/machines/{machine_id}/metadata/{key} Add or update a metadata key-value pair on a specific Machine’s config.

Path parameters

string
required
The name of the Fly App the Machine belongs to.
string
required
The ID of the Machine to update the metadata for.
string
required
A key for the metadata key-value pair to add or replace. Provide the value in the request body.

Body parameters

string
required
The value to assign to the metadata key that was passed as a path parameter.
POST/v1/apps/{app_name}/machines/{machine_id}/metadata/{key}
Status: 204 No content

Delete Machine metadata

DELETE /v1/apps/{app_name}/machines/{machine_id}/metadata/{key} Delete a metadata key-value pair on a specific Machine’s config.

Path parameters

string
required
The name of the Fly App the Machine belongs to.
string
required
The ID of the Machine to delete some metadata for.
string
required
The key of the metadata to delete.
DELETE/v1/apps/{app_name}/machines/{machine_id}/metadata/{key}
Status: 204 No content

Notes on networking

Machines are closed to the public internet by default. To make them accessible via the associated application, you need to:
  • Allocate an IP address to the Fly App
  • Add one or more services to the Machine config with ports and handlers, as shown in Create a Machine with services.
For an application with a single Machine, all requests will be routed to that Machine. A Machine in the stopped state will be started up automatically when a request arrives. For an application with multiple Machines with the same configuration, requests will be distributed across them. Warm-start behavior in this situation is not well-defined now, so should not be relied upon for apps with multiple Machines. Requests to Machines with mixed configurations will be distributed across Machines whose configurations match the request. For example, if 3 out of 6 Machines have service configurations set to listen on port 80, requests to port 80 will be distributed amongst those 3.

Reaching Machines

Machines can be reached within the private network by hostname, in the format <id>.vm.<app-name>.internal. For example, to reach a Machine with ID 3d8d413b29d089 on an app called my-app-name, use hostname 3d8d413b29d089.vm.my-app-name.internal.

Machine config object properties

Properties of the config object for Machine configuration. See Machine properties. image: string - Required. The container registry path to the image that defines this Machine (for example, “registry-1.docker.io/library/ubuntu:latest”).
auto_destroy: bool (false) - If true, the Machine destroys itself once it’s complete.
checks: An optional object that defines one or more named checks. The key for each check is the check name. The value for each check supports:
  • type: string (nil) - tcp or http.
  • port: int (nil) - The TCP port to connect to, likely should be the same as internal_port.
  • interval: int (nil) - The interval, in nanoseconds, between connectivity checks
  • timeout: int (nil) - The maximum time, in nanoseconds, a connection can take before being reported as failing its health check.
  • grace_period: int (nil) - How long to wait, in nanoseconds, before we start running health checks.
  • method: string (nil) - For http checks, the HTTP method to use to when making the request.
  • path: string (nil) - For http checks, the path to send the request to.
  • protocol: string (nil) - For http checks, whether to use http or https
  • tls_server_name: string (nil) - If the protocol is https, the hostname to use for TLS certificate validation
  • tls_skip_verify: bool (false) - For http checks with https protocol, whether or not to verify the TLS certificate
  • headers: {string: [string, string]} () - For http checks, an array of objects with string field name and array of strings field values. An example of two checks:

dns:
  • nameservers: Used for Fly Kubernetes.
  • searches: Used for Fly Kubernetes.
  • options: Used for Fly Kubernetes.
  • dns_forward_rules: Used for dedicated hosts.
  • skip_registration: boolean - If true, do not register the Machine’s 6PN IP with the internal DNS system.

env: {string:string} () - An object filled with key/value pairs to be set as environment variables.
files: An optional array of objects defining files to be written within a Machine, one of raw_value or secret_name must be provided.
  • guest_path: string - The path in the Machine where the file will be written. Must be an absolute path.
  • raw_value: string - Contains the base64 encoded string of the file contents.
  • secret_name: string - The name of the secret containing the base64 encoded file contents. An example of two files:

guest: Configure the resources allocated for this Machine. An object with the following options:
  • cpu_kind: string (nil) - The type of CPU reservation to make (“shared”, “performance”, and so on).
  • gpu_kind: string (nil) - The type of GPU reservation to make.
  • host_dedication_id: The ID of the host dedication (group of dedicated hosts) on which to create this Machine. (beta)
  • cpus: int (nil) - The number of CPU cores this Machine should occupy when it runs. (default 1)
  • gpus: int (nil) - The number of GPU cores this Machine should occupy when it runs. (default 1)
  • memory_mb: int (nil) - Memory in megabytes as multiples of 256 (default 256)
  • kernel_args: Optional array of strings. Arguments passed to the kernel.
  • persist_rootfs: string (nil) - The root filesystem will be persisted across restarts and updates. Possible values are never (default), restart, and always. See here for details.

init: Arguments for init, which is Fly.io’s footprint inside your Machine, and controls how your own code gets run.
  • exec: [string, string]([]) - The command line for the program to run once the Machine boots up. This overrides any other startup command line, either in our API or in your Docker container definition.
  • entrypoint: [string, string]([]) - A command line to override the ENTRYPOINT of your Docker container; another way to define the program that is going to start up when your Machine boots up.
  • cmd: [string, string]([]) - A command line to override the CMD of your Docker container; still another way to define the program that is going to start up when your Machine boots up.
  • kernel_args: Optional array of strings. Arguments passed to the kernel.
  • tty: bool (false) - Allocate a TTY for the process we start up.
  • swap_size_mb: int (nil) - Swap space to reserve for the Fly Machine in, you guessed it, megabytes.

metadata: {string:string} () - An object filled with key/value pairs for the Machine metadata. We use metadata internally for routing, process groups, and clusters.
metrics: An optional object defining a metrics endpoint that Prometheus on Fly.io will scrape.
  • port: int - Required. The port that Prometheus will connect to.
  • path: string - Required. The path that Prometheus will scrape (e.g. /metrics).

mounts: An array of objects that reference previously created persistent volumes. Currently, you may only mount one volume per Machine.
  • volume: string - Required. The volume ID, visible in fly volumes list. For example vol_2n0l3vl60qpv635d.
  • path: string - Required. Absolute path on the Machine where the volume should be mounted. For example, /data.
  • name: string - The name of the Volume to attach.
  • extend_threshold_percent: int - The threshold of storage used on a volume, by percentage, that triggers extending the volume’s size by the value of add_size_gb.
  • add_size_gb: int - The increment, in GB, by which to extend the volume after reaching the extend_threshold_percent. Required with extend_threshold_percent.
  • size_gb_limit: int - The total amount, in GB, to extend a volume. Optional with extend_threshold_percent.
  • encrypted: boolean - Volume is encrypted. Default true.
Volumes are tied to specific physical hosts. A Machine can only mount to a volume that exists on the same host. If you create a Machine first and then create a volume, even in the same region, there’s a good chance they’ll end up on different hosts. In that case, the volume attachment will fail.You cannot change which volume a Machine is attached to by updating the Machine’s config. If you want to use a different volume, you’ll need to destroy the Machine and create a new one that mounts to the desired volume.

processes: An optional array of objects defining multiple processes to run within a Machine. The Machine will stop if any process exits without error.
  • entrypoint: An array of strings. The process that will run.
  • cmd: An array of strings. The arguments passed to the entrypoint.
  • env: An object filled with key/value pairs to be set as environment variables.
  • env_from : An array of objects that define environment variables from Machine fields. Used for Fly Kubernetes.
  • exec: An array of strings. The command to run for Machines in this process group on startup.
  • user: string (nil) - An optional user that the process runs under.
  • ignore_app_secrets: boolean - If true, only use the secrets provided at the process level. Default false.
  • secrets: An array of strings. Set the secrets in the environment of the Machine. env_var is required and is the name of the environment variable that will be set from the secret. It must be a valid environment variable name. name is optional and when provided is used to reference a secret name where the env_var is different from what was set as the secret name.

restart: Defines whether and how flyd restarts a Machine after its main process exits. Learn more about Machine restart policies. This object has the following options:
  • policy: string - Required. One of “no”, “on-failure”, or “always”.
  • max_retries: int (nil) - The maximum number of retries when the policy is “on-failure”.

schedule: string (nil) - Optionally one of hourly, daily, weekly, monthly. Runs Machine at the given interval. Interval starts at time of Machine creation.
services: An array of objects that define a single network service. Check the Machines networking section for more information.
  • protocol: string - Required. tcp or udp. Learn more about running raw TCP/UDP services.
  • internal_port: int - Required. Port the Machine listens on.
  • concurrency: Control Fly Proxy’s load balancing for this service.
    • type: string - connections (TCP) or requests (HTTP). Default is connections. Determines which kind of event we count for load balancing.
    • soft_limit: int (nil) - Ideal service concurrency. We will attempt to spread load to keep services at or below this limit. We’ll deprioritize a Machine to give other Machines a chance to absorb traffic. Defaults to 20 when unset.
    • hard_limit: int (nil) - Maximum allowed concurrency. The limit of events at which we’ll stop routing to a Machine altogether, and, if configured to do so, potentially start up existing Machines to handle the load. Defaults to unlimited when unset.
  • ports: MachinePort - An array of objects defining the service’s ports and associated handlers. Options:
    • port: int (nil) - The internet-exposed port to receive traffic on; if you want HTTP traffic routed to 8080/tcp on your Machine, this would be 80.
    • start_port, end-port: int (nil) - Like port, but allocate a range of ports to route internally, for applications that want to occupy whole port ranges.
    • handlers: Array of protocol handlers for this port. How should the Fly Proxy handle and terminate this connection. Options include http, tcp, tls.
    • force_https: bool (false) - If true, force HTTP to HTTPS redirects.
    • http_options: Fiddly HTTP options (if you don’t know you need them, you don’t), including:
      • compress: bool (false) - If true, enable HTTP compression.
      • h2_backend: bool (false) - If true, inform Fly Proxy that your app supports HTTP/2 (h2c with prior knowledge), which enables HTTP/2 only workloads to work with the http handler.
      • response: Options for controlling HTTP response headers.
        • headers: ({“headers”: {string:string}} (nil)) HTTP headers to set on responses.
        • pristine: bool (false) - If true, do not add any Fly.io headers to HTTP responses. The following response headers won’t be added and won’t be modified if returned by the app: Server, Via, Fly-Request-Id, Fly-Cache-Status.
    • tls_options: Fiddly TLS options (if you don’t know you need to mess with these, you don’t need to), including:
      • alpn: [string, string]([]) : ALPN protocols to present TLS clients (for example, [“mqtt”]).
      • default_self_signed: bool (false) - If true, serve a self-signed certificate if no certificate exists.
      • versions: [string, string]([]) : TLS versions to allow (for instance, [“TLSv1.2”, “TLSv1.3”]).
    • proxy_proto_options: Configure the version of the PROXY protocol that your app accepts. Version 1 is the default.
      • version: A string to indicate that the TCP connection uses PROXY protocol version 2. The default when not set is version 1.
  • autostart: bool (false) - If true, Fly Proxy starts Machines when requests for this service arrive.
  • autostop: string or bool (off) - One of off (or false), stop (or true), suspend. If stop, Fly Proxy stops Machines when this service goes idle. If suspend, Fly Proxy instead suspends Machines if possible and stops them if not.
  • min_machines_running: int (nil) - When autostart is true, the minimum number of Machines to keep running at all times in the primary region.

size: A named size for the VM, e.g. performance-2x or shared-cpu-2x. Note: guest and size are mutually exclusive.
standbys: Standbys enable a Machine to be a standby for another. In the event of a hardware failure, the standby Machine will be started. Only for Machines without services. Array of strings representing the Machine IDs of Machines watch (act as standby for).
statics: Optionally serve static files.
  • guest_path: string - Required. The path inside the Machines or object storage bucket where the files to serve are located.
  • url_prefix: string - Required. The URL prefix under which to serve the static files.
  • tigris_bucket: string - The Tigris bucket where the files to serve are located.
  • index_document: string - The name of the index document, served when a request is made to the root or any of its subfolders. Only works for statics hosted on Tigris

stop_config: MachineStopConfig (nil) - Configure graceful shutdown of the Machine.
  • signal: string (nil) - The name of the signal to send to the entrypoint process on the Machine to initiate shutdown.
  • timeout: int (nil) - How long in nanoseconds to wait, after signaling the entrypoint process, before hard-shutdown of the Machine.