是否可以使用js / node aws-sdk确定我的应用程序的aws实例?

时间:2021-10-08 08:05:34

I'm creating an app that automatically scales by launching/copying an instance. If the instance is duplicated. i want my js code to determine the launced instance. I'm using AWS JavaScript SDK

我正在创建一个通过启动/复制实例来自动扩展的应用程序。如果实例重复。我希望我的js代码确定launced实例。我正在使用AWS JavaScript SDK

2 个解决方案

#1


0  

Are you trying to get information about the EC2 instance your application is running on? If so, you can send a HTTP request to http://169.254.169.254/latest/meta-data/ from your Node.js application running on the EC2 instance.

您是否尝试获取有关运行应用程序的EC2实例的信息?如果是这样,您可以从EC2实例上运行的Node.js应用程序向http://169.254.169.254/latest/meta-data/发送HTTP请求。

http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html#instancedata-data-retrieval

Is there a reason why you are not using Auto Scaling Groups to scale your application? Might be easier than implemting the scaling on your own.

您是否有理由不使用Auto Scaling Groups来扩展您的应用程序?可能比自己实现扩展更容易。

http://docs.aws.amazon.com/AutoScaling/latest/DeveloperGuide/WhatIsAutoScaling.html

#2


0  

I already know how to get my instance id inside using nodejs

我已经知道如何使用nodejs获取我的实例id

`request({
    method: "GET",
    url: 'http://169.254.169.254/latest/meta-data/public-ipv4'
} ,function(err, data){
    if(err){
        cb(err, null);
    }else{
        var public_ip = data.body;
        cb(null, public_ip);
    }
});`

#1


0  

Are you trying to get information about the EC2 instance your application is running on? If so, you can send a HTTP request to http://169.254.169.254/latest/meta-data/ from your Node.js application running on the EC2 instance.

您是否尝试获取有关运行应用程序的EC2实例的信息?如果是这样,您可以从EC2实例上运行的Node.js应用程序向http://169.254.169.254/latest/meta-data/发送HTTP请求。

http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html#instancedata-data-retrieval

Is there a reason why you are not using Auto Scaling Groups to scale your application? Might be easier than implemting the scaling on your own.

您是否有理由不使用Auto Scaling Groups来扩展您的应用程序?可能比自己实现扩展更容易。

http://docs.aws.amazon.com/AutoScaling/latest/DeveloperGuide/WhatIsAutoScaling.html

#2


0  

I already know how to get my instance id inside using nodejs

我已经知道如何使用nodejs获取我的实例id

`request({
    method: "GET",
    url: 'http://169.254.169.254/latest/meta-data/public-ipv4'
} ,function(err, data){
    if(err){
        cb(err, null);
    }else{
        var public_ip = data.body;
        cb(null, public_ip);
    }
});`