node-aws-metadata
v1.0.3
Published
Library to fetch aws metadata for the application running on EC2 instances in AWS
Downloads
10
Readme
node-aws-metadata
Library to fetch aws metadata for the application running on EC2 instances in AWS
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
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
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