node-aws-metadata

1.0.3 • Public • Published

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

Readme

Keywords

Package Sidebar

Install

npm i node-aws-metadata

Weekly Downloads

3

Version

1.0.3

License

ISC

Unpacked Size

6.57 kB

Total Files

5

Last publish

Collaborators

  • nvishwakarma