Using the API for Amazon EC2
Important
As of October 14, 2022, HTTP responses from
the Amazon EC2 APIs no longer include a reason-phrase element. As recommended by
RFC7230
We provide the Query API for Amazon EC2, as well as software development kits (SDK) for Amazon that enable you to access Amazon EC2 from your preferred programming language. For more information, see the Amazon EC2 Developer Guide.
Contents
Required knowledge
If you plan to access Amazon EC2 through an API, you should be familiar with the following:
-
XML
-
Web services
-
HTTP requests
-
One or more programming languages, such as Java, PHP, Perl, Python, Ruby, C#, or C++.
Available APIs for Amazon EC2
The Amazon EC2 Query API provides HTTP or HTTPS requests that use the HTTP verb GET or POST
and a Query parameter named Action.
Amazon provides libraries, sample code, tutorials, and other resources for software developers who prefer to build applications using language-specific APIs instead of submitting a request over HTTP or HTTPS. These libraries provide basic functions that automatically take care of tasks such as cryptographically signing your requests, retrying requests, and handling error responses, so that it is easier for you to get started.
For more information, see Create Amazon EC2 resources using an Amazon SDK in the Amazon EC2 Developer Guide.
Common query parameters
Most Amazon EC2 API actions support the parameters described in the following tables. The common parameters vary depending on whether you're using Signature Version 2 or Signature Version 4 to sign your requests. For more information, see Signing Amazon API requests in the IAM User Guide.
Parameters for Signature Version 4
| Name | Description | Required |
|---|---|---|
|
|
The action to perform. Example: |
Yes |
|
|
The API version to use. |
Yes |
|
|
The hash algorithm you use to create the request signature. Example: |
Yes |
|
|
The credential scope for the request, in the format
Example: |
Yes |
|
|
The date and time at which the request is signed, in the format YYYYMMDDThhmmssZ. The
date must match the date that's included in the credential scope for the
Example: |
Yes |
X-Amz-SignedHeaders |
The headers you are including as part of the request. At a minimum, you must include the
Example: |
Yes |
|
|
A signature derived from your secret access key. Example: |
Yes |
|
|
The temporary security token obtained through a call to Amazon Security Token Service. Example: |
No |
|
|
Checks whether you have the required permissions for the action, without actually making the request.
If you have the required permissions, the request returns |
No |
The X-Amz-Algorithm, X-Amz-Credential,
X-Amz-SignedHeaders, and X-Amz-Signature parameters can either
be specified as separate parameters in the query string, or their values can be included in
a single Authorization header. For more information, see Signing Amazon API requests in the IAM User Guide.
Parameters for Signature Version 2
| Name | Description | Required |
|---|---|---|
|
|
The action to perform. Example: |
Yes |
|
|
The API version to use. |
Yes |
|
|
The access key ID for the request sender. This identifies the account which will be charged for usage of the service. The account that's associated with the access key ID must be signed up for Amazon EC2, or the request isn't accepted. Example: |
Yes |
|
|
The date and time at which the signature included in the request expires, in the
format YYYY-MM-DDThh:mm:ssZ. For more information, see ISO 8601 Example: |
Conditional. Requests must include either Timestamp or
Expires, but cannot contain both. |
|
|
The date and time at which the request is signed,
in the format YYYY-MM-DDThh:mm:ssZ. For more information, see
ISO 8601 Example: |
Conditional. Requests must include either Timestamp or
Expires, but cannot contain both. |
|
|
The request signature. Example: |
Yes |
|
|
The hash algorithm you use to create the request signature. Valid values:
Example: |
Yes |
|
|
The signature version you use to sign the request. Set this value to Example: |
Yes |
|
|
Checks whether you have the required permissions for the action, without
actually making the request. If you have the required permissions, the request
returns |
No |
|
|
The temporary security token obtained through a call to Amazon Security Token Service. Example: |
No |
Parameter values must be URL-encoded. This is true for any Query parameter passed to Amazon EC2
and is typically necessary in the Signature parameter. Some clients do
this automatically, but this is not the norm.