• AmzonIntegrator9
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies

Hi,

 

I am Trying to generate Signature version 4 for Amazon dynamoDB ,

 trying to put an item in to table but getting signature mismach error, can any once help on this,

I followed the Amazon documentation but still facing the issue.

 

Thanks in advance.

Hi,

 

I have executed the following code which makes a call to Amazon web services and I have receieved the following exception: 

 

<Response><Errors><Error><Code>InvalidParameterValue</Code><Message>Value (2011-8-30'T'6:53:6.495'Z') for parameter Timestamp is invalid. Must be in ISO8601 format.</Message></Error></Errors><RequestID>41aa0620-6f49-48cb-aead-bed311db49d1</RequestID></Response>

 

It will be great if someone helps to fix this problem and also posts AWS S3 REST sample code. 

 

Please replace 'AWS Secret Key' and 'AWS KEY' values before executing this code.

 

public with sharing class S3Rest {

public static void testAlexaWSForAmazon() {

       // The date format is yyyy-MM-dd'T'HH:mm:ss.SSS'Z' 

       DateTime d = System.now();

       String timestamp = ''+ d.year() + '-' +d.month() + '-' +d.day() + '\'T\'' +d.hour() + ':' +d.minute() + ':' +d.second() + '.' +d.millisecond() + '\'Z\'';

       String timeFormat = d.formatGmt(timestamp);

       String urlEncodedTimestamp = EncodingUtil.urlEncode(timestamp, 'UTF-8');

       String action = 'UrlInfo';

       String inputStr = action + timeFormat;

       String algorithmName = 'HMacSHA1';

       Blob mac = Crypto.generateMac(algorithmName, Blob.valueOf(inputStr),Blob.valueOf('AWS Secrect key'));

       String macUrl = EncodingUtil.urlEncode(EncodingUtil.base64Encode(mac), 'UTF-8');

       String urlToTest = 'amazon.com';

       String version = '2005-07-11';

       String endpoint = 'http://awis.amazonaws.com/';

       String accessKey = 'AWS KEY';

       HttpRequest req = new HttpRequest();

       req.setEndpoint(endpoint +'?AWSAccessKeyId=' + accessKey +'&Action=' +

                                 action +'&ResponseGroup=Rank&Version=' +

                                  version +'&Timestamp=' + urlEncodedTimestamp +

                                  '&Url=' + urlToTest +'&Signature=' + macUrl); 

        req.setMethod('GET');

        Http http = new Http();

       try {

             HttpResponse res =   http.send(req);

             System.debug('STATUS:'+res.getStatus());

             System.debug('STATUS_CODE:'+res.getStatusCode());

             System.debug('BODY: '+res.getBody());

        } catch(System.CalloutException e) {

              System.debug('ERROR: '+ e);

         }

   }

}

 

Thanks,

Rag