Download the PHP package renoki-co/laravel-ec2-metadata without Composer
On this page you can find all versions of the php package renoki-co/laravel-ec2-metadata. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-ec2-metadata
Laravel EC2 Metadata
Retrieve the EC2 Metadata using Laravel's eloquent syntax.
🤝 Supporting
If you are using one or more Renoki Co. open-source packages in your production apps, in presentation demos, hobby projects, school projects or so, sponsor our work with Github Sponsors. 📦
🚀 Installation
You can install the package via composer:
🙌 Usage
The package was made to be easier for you to implement your own methods and keep it simple, without hassling too much about requests.
In this brief example, you can calculate the seconds left until the EC2 Spot instance will be terminated.
Setting Version
The default version of the Ec2Metadata class is latest
, but to avoid your code to break due to API changes, define the version to run on.
You can see the list of available versions in IMDSv2 documentation, under Get the available versions of the instance metadata
:
Calling Custom Endpoints
The IMDSv2 API is pretty complex, and there are some functions you can use from the Ec2Metadata
class, just for convenience. When you want to retrieve data from an endpoint that's not implemented, you can either define a macro or use the get()
and getJson()
functions to retrieve in plain-text or as a JSON-decoded array:
Take this example for retrieving the kernel ID (under /meta-data/kernel-id
):
To retrieve JSON values, you may call getJson
. This will work properly only if the expected value from the endpoint you call will be a JSON-encoded response.
In the implementation, terminationNotice
uses the getJson()
to retrieve the response:
Macros
Alternatively to using get()
and getJson()
, you can define macros:
Testing Your Code
The package is using HTTP Client, a Laravel feature that leverages Guzzle and you can handle requests and test them by mocking responses.
Testing properly your app means you should be fully trained with the AWS EC2's IMDSv2 API, in order to provider appropriate responses.
When pushing the responses in testing, make sure to take into account that the first call would be the token retrieval.
🐛 Testing
🤝 Contributing
Please see CONTRIBUTING for details.
🔒 Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
🎉 Credits
- Alex Renoki
- All Contributors
All versions of laravel-ec2-metadata with dependencies
guzzlehttp/guzzle Version ^6.5|^7.0
illuminate/http Version ^9.0
illuminate/support Version ^9.0