AWS Java SDK

Cette page est à ce jour disponible en anglais uniquement.

The AWS Java SDK helps you code by providing Java APIs for 3DS OUTSCALE Cloud services.The single, downloadable package includes the AWS Java library, code samples, and documentation.

Prerequisites

To use the AWS SDK for Java, ensure that you have the following elements:

  • A suitable Java Development Environment.

  • A 3DS OUTSCALE account and access keys. For more information, see Démarrage rapide.

  • 3DS OUTSCALE credentials (access keys) set in your environment or using the shared (by the AWS CLI and other SDKs) credentials file.

Linux and Windows Configuration

  1. Download the SDK from https://sdk-for-java.amazonwebservices.com/latest/aws-java-sdk.zip.

  2. After downloading the SDK, extract the content into a local directory.

The SDK contains the following directories:

  • documentation – Contains the API documentation, which is also available at the following address: AWS SDK for Java Reference.

  • lib – Contains the SDK .jar files.

  • samples – Contains working code samples that demonstrate how to use the SDK.

  • third-party – Contains third-party libraries that are used by the SDK, such as Apache commons logging, AspectJ and the Spring framework.

To use the SDK, add the full path to the lib and third-party directories to the dependencies in your build file, and add them to your java CLASSPATH to run your code.

Examples

The AWS SDK for Java comes packaged with a number of code samples that demonstrate many of the features of the SDK in build-able, runnable programs that you can study or modify to implement your own 3DS OUTSCALE solutions using the AWS SDK for Java.

If you want to run simple scripts, you can use Ant to easily build and run them from the command line.

Initialization

To initialize your connector on the 3DS OUTSCALE endpoint, you need to create your EC2 connection using the following code:

amazonEC2 = new AmazonEC2Client(credentials);
((AmazonEC2Client)amazonEC2).setEndpoint("https://fcu._REGION_NAME_.outscale.com");
((AmazonEC2Client)amazonEC2).setSignerRegionOverride("_REGION_NAME_");

Replace REGION_NAME with the Region you want to use.

Credentials will be loaded from the default location (~/.aws/credentials)

To get your access key ID and your secret key to allow a connection to the APIs, see Gérer vos access keys.

Scripts

In this sample, we use an EC2 client to get a list of all the Availability Zones, and all instances sorted by reservation ID:

try {
    DescribeAvailabilityZonesResult availabilityZonesResult = ec2.describeAvailabilityZones();
    System.out.println("You have access to " + availabilityZonesResult.getAvailabilityZones().size() + " Availability Zones.");

    DescribeInstancesResult describeInstancesRequest = ec2.describeInstances();
    List<Reservation> reservations = describeInstancesRequest.getReservations();
    Set<Instance> instances = new HashSet<Instance>();

    for (Reservation reservation : reservations) {
        instances.addAll(reservation.getInstances());
    }

    System.out.println("You have " + instances.size() + " Outscale EC2 instance(s) running.");
        } catch (AmazonServiceException ase) {
    System.out.println("Caught Exception: " + ase.getMessage());
        System.out.println("Reponse Status Code: " + ase.getStatusCode());
        System.out.println("Error Code: " + ase.getErrorCode());
        System.out.println("Request ID: " + ase.getRequestId());
}

To create a VPC:

  1. Import the following libraries:

    import com.amazonaws.services.ec2.model.CreateVpcRequest;
    import com.amazonaws.services.ec2.model.CreateVpcResult;
    import com.amazonaws.services.ec2.model.Vpc;
  2. Execute the following code:

    System.out.println("Creating VPC...");
    CreateVpcRequest newVPC = new CreateVpcRequest("10.10.10.10/28");
    CreateVpcResult res = ec2.createVpc(newVPC);
    Vpc vpc = res.getVpc();
    String vpcId = vp.getVpcId();
    System.out.println("Created VPC " + vpcId);

Related Pages

AWS™ et Amazon Web Services™ sont des marques de commerce d’Amazon Technologies, Inc. ou de ses affiliées aux États-Unis et/ou dans les autres pays.