Skip to content

DescribeInstances

Lists your instances, or inspects specific ones by id.

Paginated. Read every page: a client that takes the first page and stops sees a partial answer with no error.

ParameterTypeConstraints
InstanceId.Nlisti- followed by 8 or 17 hex characters. Anything else: InvalidInstanceID.Malformed
Filter.NlistSee below. Cannot be combined with InstanceId.N in a way that contradicts it
MaxResultsinteger5–1000. Cannot be combined with InstanceId.N
NextTokenstringOpaque, from a previous response. Cannot be combined with InstanceId.N
DryRunboolean

Omitting MaxResults gives up to 1000 instances per page, with a nextToken when there are more.

Filters AND together; the values within one filter OR together. Names and values are case-sensitive. Values may contain the wildcards * and ?.

Supported:

FilterMatches
instance-id
instance-typeOur name
instance-state-namepending, running, stopping, stopped, shutting-down, terminated
instance-state-code
image-id
key-name
availability-zone
launch-timeWildcards allowed
private-ip-address
ip-addressThe public address
subnet-id, vpc-id
reservation-id
launch-index
client-token
root-device-name, root-device-type
architecture
security-group-id, security-group-name
block-device-mapping.*Attached volumes
network-interface.*The instance’s interface
tag:<key>, tag-key

[!primary]

An unsupported filter is an error, not an empty result. Filters naming things this platform never reports — placement groups, IAM instance profiles, metadata options, spot fields, dedicated hosts and the rest — return InvalidParameterValue naming the filter.

Matching nothing silently would be worse: your script would report zero matches and carry on confidently with a wrong answer.

Instances are grouped into reservations, exactly as on AWS — one reservation per RunInstances call.

ElementNotes
reservationIdr-…
instanceIdi-…
imageId, instanceType, keyNameinstanceType is our name
instanceStatename and code
privateIpAddressOn your own subnet
ipAddressPublic address, when one is associated
launchTime
placement.availabilityZone
amiLaunchIndexPosition within its reservation
architecture, rootDeviceName, rootDeviceType
blockDeviceMappingAttached volumes and their attach state
groupSetSecurity groups
networkInterfaceSetThe interface, its address and its subnet
tagSet
clientTokenIf one was sent at launch
stateReason, reasonWhy it reached its current state
monitoringAlways disabled — there is no monitoring service

Elements this platform does not have are omitted, never invented. Every SDK treats an absent member as null, so nothing breaks; a fabricated value would.

StateMeaning
pendingLaunching
runningBooted. Not necessarily configured
stopping / stoppedOff. Root disk and private address retained, storage still occupied
shutting-downTerminating
terminatedGone. Root disk destroyed

A terminated instance remains visible for a short window after termination, then disappears. That window is what lets a terraform destroy observe the terminal state it waits for instead of failing on a not-found.

Reservations come back oldest first, by the creation time of their first instance; instances within a reservation by launch index. That is a stricter guarantee than AWS makes, which says order may vary — so code written against AWS is safe here.

A reservation can span a page boundary and appear as a partial entry on each side. Join on reservationId if that matters to you.

An empty page can still carry a nextToken, because filters are applied after a page is assembled. Stop when the token is absent, not when a page is empty.

CodeStatusCause
InvalidInstanceID.Malformed400The id is not the right shape
InvalidInstanceID.NotFound400No such instance — or it is another account’s, which is byte-identical
InvalidParameterValue400An unsupported filter, or MaxResults out of range
InvalidParameterCombination400MaxResults or NextToken with InstanceId.N
InvalidPaginationToken400Expired, invalid, or issued for different filters

A pagination token is tied to the filters and page size it was issued for. Changing either mid-iteration invalidates it.

Terminal window
alias sc='aws --endpoint-url https://ec2.shelfcs.com --region hel1'
sc ec2 describe-instances \
--query 'Reservations[].Instances[].[InstanceId,InstanceType,State.Name,PrivateIpAddress]' \
--output table
sc ec2 describe-instances --filters Name=tag:Name,Values=web Name=instance-state-name,Values=running
for page in ec2.get_paginator("describe_instances").paginate(
Filters=[{"Name": "instance-state-name", "Values": ["running"]}]
):
for r in page["Reservations"]:
for i in r["Instances"]:
print(i["InstanceId"], i["InstanceType"])
data "aws_instances" "running" {
instance_state_names = ["running"]
}