BookmarkSubscribeRSS Feed
mrom34
Calcite | Level 5

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?

http://docs.amazonwebservices.com/AmazonFPS/latest/FPSAdvancedGuide/index.html?APPNDX_GeneratingaSig...

Thanks a lot

Romain

4 REPLIES 4
FriedEgg
SAS Employee

What are you trying to make this call from?  What SAS software do you license?  What OS is this running on?

mrom34
Calcite | Level 5

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;

FriedEgg
SAS Employee

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:

http://docs.amazonwebservices.com/AWSECommerceService/latest/DG/index.html?RequestAuthenticationArti...

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.

mrom34
Calcite | Level 5

Thanks a lot for this very detailled explanation!

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 2229 views
  • 4 likes
  • 2 in conversation