Skip to content

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

Notifications You must be signed in to change notification settings

NiteshVishwakarma896/node-aws-metadata

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

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

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published