Kivuli

NAME

Kivuli - get AWS IAM credentials for EC2

SYNOPSIS


# In some application running on EC2

use Kivuli;
use WebService::AWS::S3;

my $k = Kivuli.new(role-name => 'my-iam-role');
my $s3 = WebService::AWS::S3.new(secret-access-key => $k.secret-access-key, access-key-id => $k.access-key-id, security-token => $k.token, region => 'eu-west-2');

# Do something with the S3

DESCRIPTION

This module enables access to AWS IAM role credentials from within an EC2 instance as described here.

The credentials supplied ( AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY,) can be used to authenticate with another AWS service that the role has been granted access to.

Because the credentials are supplied in a way that is private to the EC2 instance this is a more secure method of obtaining the credentials than, for example, putting them in a configuration file.

The token must be supplied in the headers (or as a query parameter,) for requests to the service, however some services differ as to whether it should or shouldn't be part of the signed headers in the request - please see the documentation for the service you are implementing for details.

For convenience the credentials are supplied as accessors on the object, and optionally (with the :environment switch to the constructor,) as environment variables ( AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN,) which may be useful if integrating with tools that use them.

Optionally the credentials can be refreshed if the :refresh switch is applied to the constructor, that is to say one minute before the expiration of the existing credentials, the credentials will be re-fetched when they are next accessed (if :environment is specified as well the environment variables will be refreshed immediately.) For convenience the refresh-supply will emit an event whenever the refresh is triggered, this can be tapped if other parts of the application may need to change their state.

If an attempt to retrieve the credentials fails (e.g. you are running this on somewhere other than EC2, or you are running on EC2 but no IAM role has been associated with the EC2 instance,) then an exception will be thrown.

If you are using this in an ElasticBeanstalk instance rather than directly on EC2 then you will need to use the :no-api-token switch to the constructor, this will suppress the attempt to get a temporary session token which appears not to work in the EB Docker container.

METHODS

Kivuli v0.0.4

Access AWS IAM role credentials within EC2

Authors

  • Jonathan Stowe

License

Artistic-2.0

Dependencies

Cro::HTTP::ClientJSON::ClassTest::Mock

Test Dependencies

Provides

  • Kivuli

The Camelia image is copyright 2009 by Larry Wall. "Raku" is trademark of the Yet Another Society. All rights reserved.