简体   繁体   中英

Get the next (Private) Ip address from the Amazon AWS SDK for an EC2 instance

I've been playing with the amazon AWS SDK (for NodeJS) for the last couple of days, especially with the EC2 part. I was wondering if it is possible to know what your IP-address will be before booting new instances.

I checked the documentation and google but I couldn't find an answer to this. So before I run the runInstances function I have a function that returns me the next n ip-address that will be assigned to me if I create n new instances right now.

I don't know if this is possible but I can't find anything about this.

You cannot predict the private IP address that will be assigned, but you can specify the IP address when the instance is launched.

The runInstances() command in the Amazon SDK for node.js has a PrivateIpAddress parameter that can specify the IP address to assign to the instance:

var params = {
  ImageId: 'STRING_VALUE', /* required */
  MaxCount: 0, /* required */
  MinCount: 0, /* required */
  NetworkInterfaces: [
    {
      PrivateIpAddress: 'STRING_VALUE'
    }
  /* etc */
};
ec2.runInstances(params, function(err, data) {
  if (err) console.log(err, err.stack); // an error occurred
  else     console.log(data);           // successful response
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM