Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nshafer/req_imdsv2
https://github.com/nshafer/req_imdsv2
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/nshafer/req_imdsv2
- Owner: nshafer
- License: mit
- Created: 2023-11-03T23:55:30.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-03-22T17:48:47.000Z (9 months ago)
- Last Synced: 2024-10-12T07:25:25.219Z (3 months ago)
- Language: Elixir
- Size: 12.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# ReqIMDSv2
Provides a way to automatically authenticate Req requests with the Instance Metadata Service on
an Amazon AWS EC2 instance.It does this by making a request to IMDSv2 to get a token before the main request, then attaches that token
to the request.## Features
- Integrates easily with [Req](https://hexdocs.pm/req).
- Handles the extra step of fetching and using a metadata token from IMDSv2.
- Fetches the token from the same host as the original request.
- Supports extracting the metadata token for re-use on subsequent requests.
- Can enable `:fallback_to_imdsv1` if desired, in the case that IMDSv2 fails. (highly unlikely.)## Installation
The package can be installed from [hex.pm](https://hex.pm/packages/req_imdsv2) by adding `req_imdsv2` to
your list of dependencies in `mix.exs`:```elixir
def deps do
[
{:req, "~> 0.4.0"},
{:req_imdsv2, "~> 0.1.0"}
]
end
```## Documentation
Documentation is available from [hexdocs.pm](https://hexdocs.pm/req_imdsv2).
## Usage
This will work on an instance that has IMDSv2 required, and will not answer to IMDSv1 requests.
```elixir
Req.new(url: "http://169.254.169.254/latest/meta-data/instance-id")
|> ReqIMDSv2.attach()
|> Req.get!().body
"i-1234567890abcdef0"
```See the `ReqIMDSv2` module for more information and examples.