# @aws-sdk/ec2-metadata-service

> [![NPM version](https://img.shields.io/npm/v/@aws-sdk/ec2-metadata-service/latest.svg)](https://www.npmjs.com/package/@aws-sdk/ec2-metadata-service) [![NPM downloads](https://img.shields.io/npm/dm/@aws-sdk/ec2-metadata-service.svg)](https://www.npmjs.com/

Latest version **3.1136.0** (published 2026-09-18) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @aws-sdk/ec2-metadata-service
pnpm add @aws-sdk/ec2-metadata-service
yarn add @aws-sdk/ec2-metadata-service
bun add @aws-sdk/ec2-metadata-service
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; recently updated; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 3.1136.0 |
| Published | 2026-09-18 |
| First published | 2024-03-19 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=20.0.0 |
| Dependencies | 5 |
| Unpacked size | 37.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3646 |
| Author | AWS SDK for JavaScript Team |
| Maintainers | amzn-oss, aws-sdk-bot |

## Links

- npm: https://www.npmjs.com/package/@aws-sdk/ec2-metadata-service
- Repository: https://github.com/aws/aws-sdk-js-v3
- Homepage: https://github.com/aws/aws-sdk-js-v3/tree/main/packages/ec2-metadata-service
- Issues: https://github.com/aws/aws-sdk-js-v3/issues
- npm.io page: https://npm.io/package/@aws-sdk/ec2-metadata-service

## Dependencies (5)

- [tslib](https://npm.io/package/tslib.md) ^2.6.2
- [@smithy/core](https://npm.io/package/@smithy/core.md) ^3.33.3
- [@smithy/types](https://npm.io/package/@smithy/types.md) ^4.17.2
- [@aws-sdk/types](https://npm.io/package/@aws-sdk/types.md) ^3.974.5
- [@smithy/node-http-handler](https://npm.io/package/@smithy/node-http-handler.md) ^4.11.3

## Recent versions

- 3.1136.0 (latest) — 2026-09-18
- 3.1135.0 — 2026-09-17
- 3.1134.0 — 2026-09-16
- 3.1133.0 — 2026-09-15
- 3.1132.0 — 2026-09-14
- 3.1131.0 — 2026-09-11
- 3.1130.0 — 2026-09-10
- 3.1129.0 — 2026-09-09
- 3.1128.0 — 2026-09-08
- 3.1127.0 — 2026-09-04
- 3.1126.0 — 2026-09-03
- 3.1125.0 — 2026-09-02
- 3.1124.0 — 2026-09-01
- 3.1123.0 — 2026-08-31
- 3.1122.0 — 2026-08-31
- … 356 more at https://npm.io/package/@aws-sdk/ec2-metadata-service/versions

## README

# @aws-sdk/ec2-metadata-service

[![NPM version](https://img.shields.io/npm/v/@aws-sdk/ec2-metadata-service/latest.svg)](https://www.npmjs.com/package/@aws-sdk/ec2-metadata-service)
[![NPM downloads](https://img.shields.io/npm/dm/@aws-sdk/ec2-metadata-service.svg)](https://www.npmjs.com/package/@aws-sdk/ec2-metadata-service)

This package provides utils to access [EC2 Instance Metadata Service (IMDS)](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html) 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

```JavaScript
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

```JavaScript
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](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/configuring-instance-metadata-service.html).

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()](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-credential-providers/Variable/fromInstanceMetadata/) method.

---
_Source: https://npm.io/package/@aws-sdk/ec2-metadata-service · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
