function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Raghu Natha 2Raghu Natha 2 

AWS SNS integration Problem

Is there a rereference example for salesforce and Amazon SNS Integration ?  
Amit Shingavi 8Amit Shingavi 8
Hey Raghu,

Please refer following blog chain, Author has described all the steps required for the integration -
Part 1 - http://eternussolutions.blogspot.in/2015/03/salesforce-to-amazon-integration-using.html
Part 2 - http://eternussolutions.blogspot.in/2015/04/salesforce-to-amazon-integration-using.html (http://eternussolutions.blogspot.in/2015/04/salesforce-to-amazon-integration-using.html)

Do reply if you need any other help. Please mark this as a best answer if It gave you all the required insights.
Happy Coding!
 
Raghu Natha 2Raghu Natha 2
Amit,

Thank you for the response
I am trying to connect to SNS and the documentation still shows Version 2 for calculating the signature. So please let me know the changes required for below code

String Hostname='sns.us-east-1.amazonaws.com';
String formattedDateString = Datetime.now().formatGMT('EEE, dd MMM yyyy HH:mm:ss z');
String key = '$$$';
String method = 'GET'; 
String secret = '######################';

String stringToSign = 'GET\n' +
            'sns.us-east-1.amazonaws.com\n' +
            '/\n' + 'Action=ListTopics&SignatureVersion=2&SignatureMethod=HmacSHA256&Timestamp='+formattedDateString+'&AWSAccessKeyId='+key;

Blob mac = Crypto.generateMac('HmacSHA256', blob.valueof(stringToSign),blob.valueof(secretKey));
String sig = EncodingUtil.base64Encode(mac);

String url = 'http://'+Hostname+'/?'+'Action=ListTopics&SignatureVersion=2&SignatureMethod=HmacSHA256&Timestamp='+date1+'&AWSAccessKeyId='+key+'&Signature='+EncodingUtil.UrlEncode(EncodingUtil.base64Encode(mac),'UTF-8');     
        system.debug('URL: ' + url);

    http h=new http();
    Httprequest req=new Httprequest();
    Httpresponse res=new Httpresponse();
    req.setEndpoint(url);
    req.setMethod('GET');
    res = h.send(req);
    System.debug('MYDEBUG: ' + ' RESPONSE STRING: ' + res.toString());
    System.debug('MYDEBUG: ' + ' RESPONSE STATUS: '+ res.getStatus());
    System.debug('MYDEBUG: ' + ' STATUS_CODE:'+ res.getStatusCode());
    System.debug('MYDEBUG: ' + ' GET_BODY:'+ res.getBody());

Output
I see the below error :
<Message>The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.</Message>