With the AWS CLI ec2 describe-instance-types
I can get a list of all the EC2 instance types but Sagemaker Instance Types like ml.t3.medium
, ml.t3.large
, ml.m5.xlarge
, etc are not there.
aws ec2 describe-instance-types --filters "Name=instance-type,Values=ml.*" --query "InstanceTypes[].{Type: InstanceType, MaxENI: NetworkInfo.MaximumNetworkInterfaces, IPv4addr: NetworkInfo.Ipv4AddressesPerInterface}" --output table
# returns no results
I know I can get the list of SageMaker Instance Types from https://aws.amazon.com/sagemaker/pricing/ but I really want to get it programmatically.
How can I get programatically the list of instance types supported in Sagemaker for a given region?
2
Answers
Building upon the answer from Gili.
Using the aws CLI and jq :
it uses
aws pricing get-products
--region us-east-1
is important because the Pricing service is not widely available--filters Type=TERM_MATCH,Field=regionCode,Values=eu-north-1
to restrict the listing to products ineu-north-1
region, the number of products for AmazonSageMaker alone across all regions is huge, so better to let AWS to filter out those earlyjq
is used to further filter the output, it seems it's not possible to filter byproductFamily
at theaws pricing get-products
so we need to do it withjq
-r
removes the quotes from the output.PriceList[]
will iterate over all the prices returned byaws pricing get-products
fromjson
will parse the each string as JSON (.PriceList
is an array of strings)select(.product.productFamily == "ML Instance")
will filter out all other products.product.attributes.instanceName
extracts the instance type from each product.You can get the list of ml instances with this CLI call (doc):
You’ll need to filter the results further.
Note that a particular ml instance type might be available for a certain SageMaker feature like training, but not for inference. And be available in one region but not another.
If you’re end goal is to get technical details, you could first fine the relevant ml.* instances (maybe even with regex), then use the EC2 describe instance type to get more details (just strip down the
ml.
prefix).You can find relevant Python code in the "Total Cost" section of my notebook here.