Giter Club home page Giter Club logo

node-aws-metadata's Introduction

node-aws-metadata

Library to fetch aws metadata for the application running on EC2 instances in AWS

Instance metadata is available from your running instance, you do not need to use the Amazon EC2 console or the AWS CLI. This can be helpful when you're writing scripts to run from your instance. For example, you can access the local IP address of your instance from instance metadata to manage a connection to an external application.

Instance metadata is divided into categories. For a description of each instance metadata category, see Instance metadata categories below.

NPM npm bundle size npm JavaScript Style Guide

Installation

This is a Node.js module available through the npm registry.

Before installing, download and install Node.js. Node.js 12 or higher is required.

npm install --save node-aws-metadata

The top-level metadata items can be fetched

  • ami-id

  • ami-launch-index

  • ami-manifest-path

  • hostname

  • instance-action

  • instance-id

  • instance-type

  • local-hostname

  • local-ipv4

  • profile

  • public-hostname

  • public-ipv4

  • placement/availability-zone

  • placement/availability-zone-id

  • placement/region

Usage

const AWSMetaData = require('node-aws-metadata');

// To Get Instance Meta Data by a meta data category
const getInstanceData = async() =>{
    try{
        const _aws_metadata = new AWSMetaData();
        const metadata = await _aws_metadata.getInstanceMetaData('ami-id');
        console.log(metadata);
    }
    catch(err=>{
        console.log(err);
    })
    
}

// To Get Instance Avaliable Meta Data
const getInstanceAllMetaData = async() =>{
    try{
        const _aws_metadata = new AWSMetaData();
        const metadata = await _aws_metadata.getInstanceAvailableMetaData();
        console.log(metadata);
    }
    catch(err=>{
        console.log(err);
    })
    
}

Outputs

Output displayed below will have same format, content might defer below content for response is not shown.


getInstanceMetaData('ami-id') :

{ 
    'ami-id': 'amazon-linux-image-id' 
}

getInstanceAvailableMetaData()

{
  'ami-id': '',
  'ami-launch-index': ,
  'ami-manifest-path': '',
  'hostname': '',
  'instance-action': '',
  'instance-id': '',
  'instance-type': 't2.micro',
  'local-hostname': '',
  'local-ipv4': '',
  'profile': '',
  'public-hostname': '',
  'public-ipv4': '',
  'placement/availability-zone': 'us-west-1',
  'placement/availability-zone-id': '',
  'placement/region': 'us-west-1'
}

License

ISC © NiteshVishwakarma896

node-aws-metadata's People

Contributors

niteshvishwakarma896 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.