AWS Developer Tools Blog

Announcing CORS Support for Amazon EC2

We are pleased to announce that Amazon EC2 now supports CORS requests, which means you can now use the AWS SDK for JavaScript in the Browser to access your Amazon EC2 resources.

The following example code snippet shows how to make requests to Amazon EC2:

In your HTML file:

<script src="https://sdk.amazonaws.com/js/aws-sdk-2.1.34.min.js"></script>

In your JavaScript file:

var ec2 = new AWS.EC2({region: 'us-west-2'});

ec2.describeInstances(function(err, data) {
  if (err) {
    console.log(err);
  } else {
    data.Reservations.forEach(function(reservation) {
      reservation.Instances.forEach(function(instance) {
        console.log(instance.InstanceId);
      });
    });
  }
});

With Amazon EC2 support for CORS requests, you can now build rich two-tier web applications to manage your instances, VPCs, and more using the AWS SDK for JavaScript in the Browser. Check out our API documentation for details about how to use the API.

We hope you are excited to use use the Amazon EC2 API directly from the browser. We’re eager to know what you think, so leave us a comment or tweet about it @awsforjs.