JSPM

  • Created
  • Published
  • Downloads 484985
  • Score
    100M100P100Q277616F
  • License Apache-2.0

Package Exports

    This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@aws-sdk/ec2-metadata-service) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

    Readme

    @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.