@aws-sdk/ec2-metadata-service
TypeScript icon, indicating that this package has built-in type declarations

3.797.0 • Public • Published

@aws-sdk/ec2-metadata-service

NPM version NPM downloads

This package provides utils to access EC2 Instance Metadata Service (IMDS) from the AWS SDK for JavaScript v3.

Usage

The basic usage of EC2 IMDS utils in the AWS SDK for JavaScript v3 is as follows:

JavaScript example

const { MetadataService } = require("@aws-sdk/ec2-metadata-service");

const metadataService = new MetadataService({});
const token = await metadataService.fetchMetadataToken(); // fetches token explicitly
const metadata = await metadataService.request("/latest/meta-data/", {}); // request metadata from IMDSv2 (uses a token to make the request by default if `disableFetchToken` is not set to true)

ES6 example

import { MetadataService } from "@aws-sdk/ec2-metadata-service";

const metadataService = new MetadataService({});
const token = await metadataService.fetchMetadataToken(); // fetches token explicitly
const metadata = await metadataService.request("/latest/meta-data/", {}); // request metadata from IMDSv2 (uses a token to make the request by default if `disableFetchToken` is not set to true)

Notes

Note that by default, requests to IMDS are in accordance with IMDSv2.

Read more about Instance Metadata here: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html

The @aws-sdk/ec2-metadata-service package is a standalone utility and not part of the default credential provider chain. If you want to use IMDS for credentials, you can use the fromInstanceMetadata() method.

Readme

Keywords

none

Package Sidebar

Install

npm i @aws-sdk/ec2-metadata-service

Weekly Downloads

57,152

Version

3.797.0

License

Apache-2.0

Unpacked Size

32.1 kB

Total Files

22

Last publish

Collaborators

  • amzn-oss
  • aws-sdk-bot