Find the Amazon Linux 2023 AMI for your region, launch a t2.micro instance with run-instances, wait for running state, and terminate ā all from the CLI.
Query EC2 for the most recent Amazon Linux 2023 AMI in your active region. AMI IDs are region-specific ā the ID that works in us-east-1 will not work in eu-west-1.
AMI_ID=$(aws ec2 describe-images \
--owners amazon \
--filters "Name=name,Values=al2023-ami-2023*" \
"Name=architecture,Values=x86_64" \
--query "Images | sort_by(@, &CreationDate) | [-1].ImageId" \
--output text)echo "AMI ID: $AMI_ID"Amazon Linux 2023 AMIs are published by Amazon (owner ID amazon).
The filter on al2023-ami-2023* scopes results to standard AL2023 images ā the 2023 after the prefix matters, because a looser al2023-ami-* pattern would also match al2023-ami-minimal-* (stripped-down images without common tools).
The x86_64 filter excludes ARM images. sort_by(@, &CreationDate) | [-1] selects the newest image.
The result is stored in a shell variable so every subsequent command can reference it without retyping the long ID.
AMI ID: ami-0abcdef1234567890
The exact ID will differ by region and change as Amazon publishes new AMIs.
Any value starting with ami- is correct.