How to get a list of available instance types on Amazon EC2?

后端 未结 2 701
日久生厌
日久生厌 2021-01-25 00:50

Is there an API to get a list of available instance types on EC2?

I can see that there is a price list JSON file that you can download but it\'s 70 megabytes which is no

相关标签:
2条回答
  • 2021-01-25 01:28

    This information is available as part of the EC2 API. The API defines various resource shapes which can be exposed by language-specific SDKs. For example, the Python library botocore (which also powers the AWS CLI) exposes instance types via the EC2 service model:

    import botocore.session
    
    sess = botocore.session.Session()
    available_types = sess.get_service_model('ec2').shape_for('InstanceType').enum
    

    If you're working with EC2 from Python, there's a good chance you're working with the higher level boto3 library. A boto3 EC2 client will already have a reference to the underlying botocore service mode, so you can do this instead:

    client = boto3.client('ec2')
    client._service_model.shape_for('InstanceType').enum
    

    SDKs for other languages should also expose the InstanceType resource shape. Since this comes directly from the API and tends to be automatically pushed to the SDK repos, the data should be common as long as you're using the same API version (compare the JSON API definition in botocore and the JavaScript SDK, for instance).

    0 讨论(0)
  • 2021-01-25 01:37

    There is no API to retrieve a list of Amazon EC2 instance types.

    You could use some 3rd-party sites:

    • http://www.ec2instances.info/
    • http://ec2pricing.net/
    • https://gist.github.com/ilyash/4573706
    0 讨论(0)
提交回复
热议问题