DATA Step, Macro, Functions and more

Connecting to amazon web service

Posts: 24

Connecting to amazon web service


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


Trusted Advisor
Posts: 1,318

Connecting to amazon web service

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

Posts: 24

Connecting to amazon web service

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 "


AWSAccessKeyId= [Access Key ID]&







data _null_ ;

infile amazon truncover;


put _infile_;


Trusted Advisor
Posts: 1,318

Connecting to amazon web service

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:

The process you are missing is outlined here:

You need to outsource this key generation to a different technology, for instance, perl...

Download perl here:

Now you need to install the Digest:Smiley FrustratedHA:Smiley TongueurePerl 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:Smiley FrustratedHA:Smiley TongueurePerl'

If you encounter problems try this site:

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:Smiley FrustratedHA:Smiley TongueurePerl 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 '';

  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';


filename key pipe 'C:\path\to\ C:\mytempfile myaws_secretkey';

data foo;

  infile key;

  input key $;


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.

Posts: 24

Connecting to amazon web service

Thanks a lot for this very detailled explanation!

Ask a Question
Discussion stats
  • 4 replies
  • 2 in conversation