Configuring AWS EC2 in Nodejs

Source: Internet
Author: User

    1. Get access key and secret access key
The option to have security credentials under your account and click Access Keys to create new access key as prompted
    1. Installing the SDK
npm Install AWS-SDK--saveIn App.js, the declaration references Aws-sdk var AWS = require (' aws-sdk ');
    1. Configuring the EC2 Service
         Under Project Root, create a new file Config.json, and enter the following to save { "Accesskeyid": "your_own_access_key_id", "Secretaccesskey": "Your_own_secret_access_key" , "region": "Your_own_instance_region" }          In App.js, the configuration file before loadAWS.config.loadFromPath ('./config.json ');Then configure EC2 var ec2 = new AWS. EC2 ({region: ' us-west-1 '});
    1. Create Instance
1 //Create The instance2Ec2.runinstances (params,function(err, data) {3   if(err) {4Console.log ("Could not create instance", err);5     return;6   }7 8   varInstanceId = data. Instances[0]. InstanceId;9Console.log ("Created instance:", instanceId);Ten  One   //ADD Tags to the instance Aparams = { - Resources: [InstanceId], - Tags: [{ theKey: ' Name ', -Value: ' test_01 ' -     }] -   }; +  -Ec2.createtags (params,function(err) { +Console.log ("Tagging instance", err?) "Failure": "Success"); A   }); at});

Reference: Http://docs.aws.amazon.com/AWSJavaScriptSDK/guide/node-configuring.html Http://docs.aws.amazon.com/AWSJav          Ascriptsdk/guide/node-examples.html http://docs.aws.amazon.com/AWSJavaScriptSDK/guide/node-services.html Http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/EC2.html  

Configuring AWS EC2 in Nodejs

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.