AWS Developer Tools Blog
Announcing CORS Support for HAQM EC2
We are pleased to announce that HAQM EC2 now supports CORS requests, which means you can now use the AWS SDK for JavaScript in the Browser to access your HAQM EC2 resources.
The following example code snippet shows how to make requests to HAQM EC2:
In your HTML file:
<script src="http://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 HAQM 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 HAQM EC2 API directly from the browser. We’re eager to know what you think, so leave us a comment or tweet about it @awsforjs.