Hi,
I am trying to connect ot amazon web service form SAS but I can't find it how to generate the signature parameter. In their documentation, they say we need this HMAC-SHA256 parameter in the query. Do you have any code to generate it?
Thanks a lot
Romain
What are you trying to make this call from? What SAS software do you license? What OS is this running on?
I am just trying to play with the web service. I found this code and I believe it is not working because amazon added the signature parameter after this paper was released. I am using SAS 9.2 on win 7
filename amazon url "http://ecs.amazonaws.com/onca/xml?
Service=AWSECommerceService&
AWSAccessKeyId= [Access Key ID]&
Operation=ItemLookup&
ItemId=B00008OE6I&
IdType=ASIN&"
lrecl=2000
recfm=S
;
data _null_ ;
infile amazon truncover;
input;
put _infile_;
run;
In order to generate a key in SAS that uses sha256 or sha1 you need to license SAS/Secure software. There are ways around this by using other programs. The link you provided is for the FPS (Flexible Payments Service), which is not what you are actually trying to utilize based on the code above. You are trying to interact with the AWSECommerceService.
This is the proper documentation for that API you are attempting to interact with:
You should make sure you are using for proper secret keys first: http://docs.amazonwebservices.com/AWSECommerceService/latest/DG/index.html?ViewingCredentials.html
The process you are missing is outlined here: http://docs.amazonwebservices.com/AWSECommerceService/latest/DG/index.html?rest-signature.html
You need to outsource this key generation to a different technology, for instance, perl...
Download perl here: http://www.activestate.com/activeperl/downloads
Now you need to install the Digest::SHA::PurePerl module (There is another version that is faster but requires C/C++ compilers, this one should present you with fewer problems, unless you know what you are doing).
In a command prompt window you want to type ppm install 'Digest::SHA::PurePerl'
If you encounter problems try this site: http://www.activestate.com/blog/2010/10/how-install-cpan-modules-activeperl
Now that you have perl and the digest module installed you will want to create a perl script to call from SAS that will return the key you want. It should look something like this: (note everything below is written quickly and not tested, at all)
#! usr/bin/perl
use FileHandle;
open INFILE, '<', $ARGV[0] or die "error opening $ARGV[0]: $!";
my $data = do { local $/; <INFILE> };
use Digest::SHA::PurePerl qw(hmac_sha256_base64);
$digest=hmac_sha256_base64($data, $ARGV[1]);
print $digest;
close INFILE;
From SAS you would want to call this:
data _null_;
file 'C:\mytempfile' lrecl=5000 termstr=cr;
put 'GET';
put 'ecs.amazonaws.com';
put '/onca/xml';
put 'AWSAccessKeyId=00000000000000000000&ItemId=0679722769&Operation=ItemLookup&ResponseGroup=ItemAttributes%2COffers%2CImages%2CReviews&Service=AWSECommerceService&Timestamp=20090101T12%3A00%3A00Z&Version=2009-01-06';
run;
filename key pipe 'C:\path\to\perlscript.pl C:\mytempfile myaws_secretkey';
data foo;
infile key;
input key $;
run;
Now you have what you need to build the full url including the HMAC-SHA Signature... Of course a full and proper implementation of this will be much more complex.
Thanks a lot for this very detailled explanation!
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.