sysadmin

Life in the digital trenches

Net::Amazon::SignatureVersion4

GitHub

CPAN

Status

Early release, but complete. This module is not actively maintained. If you wish to use it, please let me know and I’ll get it updated This is a complete implementation of the Signature Version 4 Signing Process. It passes all complete tests provided by Amazon.

URI::Encode version 0.08 made some changes in its default behavior. This change caused some of the tests to fail for this module. Release version 0.006 explicitly sets the desired behavior of URI::Encode. Please upgrade to version 0.006 as it works with all versions of URI::Encode.

Description

This module signs requests destined for a service that requires version 4. Currently, it has only been tested on Amazon’s Glacier service. It should work on any service. If you have issues with other services, please let me know by opening an issue.

Synopsis

use Net::Amazon::SignatureVersion4;

my $sig=new Net::Amazon::SignatureVersion4();
my $hr=HTTP::Request->new('GET','http://glacier.us-west-2.amazonaws.com/-/vaults', [ 
			   'Host', 'glacier.us-west-2.amazonaws.com', 
			   'Date', strftime("%Y%m%dT%H%M%SZ",gmtime(time())) , 
			   'X-Amz-Date', strftime("%Y%m%dT%H%M%SZ",gmtime(time())) , 
			   'x-amz-glacier-version', '2012-06-01',
		       ]);
$hr->protocol('HTTP/1.1');

$sig->set_request($request); # $request is HTTP::Request
$sig->set_region('us-west-2');
$sig->set_service('glacier'); # Must be service you are accessing
$sig->set_Access_Key_ID('AKIDEXAMPLE'); # Replace with your ACCESS_KEY_ID
$sig->set_Secret_Access_Key('wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY'); # Replace with your SECRET_KEY
my $authorized_request=$sig->get_authorized_request();
my $agent = LWP::UserAgent->new( agent => 'perl-Net::Amazon::SignatureVersion4-Testing');
my $response = $agent->request($authorized_request);
if ($response->is_success) {
    say("List of vaults");
    say($response->decoded_content);  # or whatever
    say("Connected to live server");
}else {
    say($response->status_line);
    use Data::Dumper;
    say("Failed Response");
    say(Data::Dumper->Dump([ $response ]));
}