Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

365
Visualizações
NodeJs - Detect whether app is on AWS or local

Is there a way in NodeJs to detect whether it's currently running on an EC2 instance or whether it's being run locally? I have some functionality that changes based on where it's deployed. I can detect the IP address but I want something more dynamic, not tied to specific server configurations.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

We could hit EC2 Metadata endpoint to determine EC2 instance or not.

This curl woks only within an EC2 instance

curl http://169.254.169.254/latest/meta-data/

Library node-ec2-metadata exposes an easy to use method which calls this metadata service behind the scenes.

var metadata = require("node-ec2-metadata");

metadata.isEC2().then(function (onEC2) {
  console.log("Running on EC2? " + onEC2);
});

Point to keep in mind, straight from the docs(since they hit the HEAD url and timeout after 500ms):

The initial call may take up to 500ms on a non-EC2 host, but the result is cached so subsequent calls provide a result immediately

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda