# @everymundo/aws-instance-identity

> Returns information about the AWS Instance that calls it

Latest version **0.2.0** (published 2018-12-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install @everymundo/aws-instance-identity
pnpm add @everymundo/aws-instance-identity
yarn add @everymundo/aws-instance-identity
bun add @everymundo/aws-instance-identity
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2018-12-17 |
| First published | 2018-03-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Daniel Santana |
| Maintainers | alexandprivate, anahiem, avivero93, ballester, caviola, christopherepm, danielsan, darielnoel, davidxl, devrchancay, emdavidmoreno, erlin, ernestocarrasco, everymundo-admin, gallegogt, herlin, hugopalomares, jonmorazav, joseivansandoya, karinfdez, mvcruzata, neilgoldman, raymer, yartiles |

## Links

- npm: https://www.npmjs.com/package/@everymundo/aws-instance-identity
- Repository: https://github.com/EveryMundo/aws-instance-identity
- Homepage: https://github.com/EveryMundo/aws-instance-identity#readme
- Issues: https://github.com/EveryMundo/aws-instance-identity/issues
- npm.io page: https://npm.io/package/@everymundo/aws-instance-identity

## Dependencies (2)

- [socks-proxy-agent](https://npm.io/package/socks-proxy-agent.md) ^4.0.1
- [@everymundo/promise-data-to](https://npm.io/package/@everymundo/promise-data-to.md) ^1.2.1

## Recent versions

- 0.2.0 (latest) — 2018-12-17
- 0.1.1 — 2018-03-21
- 0.1.0 — 2018-03-21
- 0.0.2 — 2018-03-19
- 0.0.1 — 2018-03-19
- 0.0.0 — 2018-03-15

## README

# @everymundo/aws-instance-identity
Returns information about the AWS Instance that calls it


## Installation
```sh
npm install @everymundo/aws-instance-identity
```

## Usage

### With promise
```js
const { getIdentityDocument } = require('@everymundo/aws-instance-identity');
getIdentityDocument()
  .then((result) => {
    console.log(result);
  })
  .catch((err) => {
    console.error(err);
  });
```


### With async/await
```js
const { getIdentityDocument } = require('@everymundo/aws-instance-identity');

const init = async() => {
  try {
    const result = getIdentityDocument();
    console.log(result);
  } catch (e) {
    console.error(err);
  }
}
```

## Running outside AWS servers

When running locally it will fail the request since that request is done to an endpoint that
only works inside the aws infrastructure.

#### With Socks Proxy
If you really want to get a document you can do so by running a socks proxy with an AWS instance
via ssh. The connection can be stablished by running the following command:

```sh
# You should replace your-instance-address by your instance address
ssh -ND 8157 your-instance-address &> /dev/null & PID=$! && echo $PID
```

After that you can just set the environment variable ```SOCKS_PROXY=socks://127.0.0.1:8157``` and run your aplication.

You can try that out in a node console
```sh
SOCKS_PROXY=socks://127.0.0.1:8157 node -e "require('@everymundo/aws-instance-identity').getIdentityDocument().then(console.log)"
```
The output would be similar to this:
```js
{
  privateIp: '192.168.0.12',
  devpayProductCodes: null,
  availabilityZone: 'us-west-1a',
  version: '2010-08-31',
  instanceId: 'i-2093840273489',
  billingProducts: null,
  instanceType: 'm4.xlarge',
  accountId: '98237498273984',
  architecture: 'x86_64',
  kernelId: null,
  ramdiskId: null,
  imageId: 'ami-34cb443',
  pendingTime: '2017-10-20T20:41:03Z',
  region: 'us-west-1'
}
```

#### Without Socks Proxy
This should bring you an error
```sh
node -e "require('@everymundo/aws-instance-identity').getIdentityDocument().catch(console.error)"
```
The error message would be something similar to this:
```js
{ code: 599,
  start: 2018-03-21T04:35:54.692Z,
  end: 1521606957775,
  err:
   { Error: connect EHOSTUNREACH 169.254.169.254:80
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1170:14)
     errno: 'EHOSTUNREACH',
     code: 'EHOSTUNREACH',
     syscall: 'connect',
     address: '169.254.169.254',
     port: 80 },
  attempt: 1,
  endpoint: 'http://169.254.169.254/latest/dynamic/instance-identity/document' }
```

---
_Source: https://npm.io/package/@everymundo/aws-instance-identity · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
