[A] Boto Client
[Credentials] aws_access_key_id= <cloudstack_api_key> aws_secret_access_key= <cloudstack_secret_key>
For more details on Boto configuration refer [1]
import boto import boto.ec2 region = boto.ec2.regioninfo.RegionInfo(name="AmazonEC2", endpoint="<cloudstack_management_server_ip>") conn = boto.connect_ec2(aws_access_key_id="<cloudstack_api_key>", aws_secret_access_key="<cloudstack_secret_key>", is_secure=False, region=region, port=7080, path="/awsapi", api_version="2012-08-15") conn.get_all_images()
For a complete list off Boto EC2 API calls refer [2]
[B] Java SDK
Download source from [3]. For general guidelines on how to use the SDK, refer [4].
Below is a sample Java code that uses the SDK to make EC2 DescribeImages API call against CloudStack,
AWSCredentials credentials = null; String endpoint = "http://<cloudstack_management_server_ip>:7080/awsapi/"; Protocol protocol = Protocol.HTTP; int timeout = 600 * 1000; // Extract AWS_ACCESS_KEY and AWS_SECRET_KEY from AwsCreadentials.properties file try { credentials = new PropertiesCredentials(InlineGettingStartedCodeSampleApp.class.getResourceAsStream("AwsCredentials.properties")); } catch (IOException e1) { System.out.println("Credential were not properly entered into AwsCredntials.properties."); System.exit(-1); } // Create a Client configuration object to control how the client connects to CloudStack e.g. retry counts ClientConfiguration client = new ClientConfiguration(); client.setProtocol(protocol); client.setSocketTimeout(timeout); // Create a Amazon EC2Client object to call any EC2 API ec2 = new AmazonEC2Client(credentials, client); ec2.setEndpoint(endpoint); // Use the Amazon client object to make the api call DecsribeImages DescribeImagesRequest imagesRequest = new DescribeImagesRequest(); DescribeImagesResult imagesResult = ec2.describeImages(imagesRequest); System.out.println("DescribeImages: " + imagesResult);
Note: Before running the sample, place it in the samples _folder and fill in AwsCredentials.properties with _accessKey=<cloudStack_api_key> and secretkey=<cloudstack_secret_key>
One can use the AWS Toolkit for Eclipse to add the AWS SDK for Java to an existing project, or create a new Java project based on the SDK [5].
[C] PHP SDK
Download source from [6]. For general guidelines on how to use the SDK, refer [7].
Below is a sample PHP code that uses the SDK to make EC2 DescribeImages API call against CloudStack,
<?php error_reporting(-1); header("Content-type: text/html; charset=utf-8"); require_once '../sdk.class.php'; $ec2 = new AmazonEC2(); $ec2->set_hostname('http://< cloudstack_management_server_ip >:7080/awsapi/'); $ec2->disable_ssl(); $ec2->set_max_retries(0); $response = $ec2->describe_images(); echo "\nDescribeImages \n"; print_r($response->body); ?>
Note: Before running the sample in _samples folder, rename config-sample.inc.php to config.inc.php _and write into the file with ‘key’=><cloudStack_api_key> and ‘secret’=><cloudstack_secret_key>_
[1] http://docs.pythonboto.org/en/latest/boto_config_tut.html
[2] http://docs.pythonboto.org/en/latest/ref/ec2.html#module-boto.ec2.connection
[3] http://aws.amazon.com/sdkforjava/
[4] http://aws.amazon.com/articles/3586?_encoding=UTF8&jiveRedirect=1
[5] http://aws.amazon.com/eclipse/
[6] http://aws.amazon.com/sdkforphp/
[7] http://aws.amazon.com/articles/4261?_encoding=UTF8&jiveRedirect=1