+ Start a Discussion
rekha sharmarekha sharma 

PUT Object COPY REST API- AWS s3 Integration : getting exception

Hi All i am using amazon s3 rest API For put copyhttp://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectCOPY.html.

I am sending all the header and required parameters but i am getting exception

<Error><Code>RequestTimeout</Code><Message>Your socket connection to the server was not read from or written to within the timeout period. Idle connections will be closed.</Message><RequestId>29BB7877BC9BBB2F</RequestId><HostId>AzGJ4IF1Uf4olokB9eB13kNFHQTKns0jCpUqXy2HnHKZQzoEPFgd+y1DYXrV8yWUq+PmZk+dV9gkDXpEIVYK5V1ouB0WfgTP</HostId></Error>

Below is Code i am using , this can be executed from console also.

String region='us-west-2';
        String method = 'PUT';
        String key= 'XXXXXXXX';
        String filename = 'Doc.pdf';
        String formattedDateString = Datetime.now().format('EEE, dd MMM yyyy HH:mm:ss z','America/Denver');    
        HttpRequest req = new HttpRequest();
        Http http = new Http();
        req.setHeader('Host','DestinationBucket.s3.amazonaws.com');  //path style
        req.setHeader('x-amz-metadata-directive', 'COPY');
        req.setHeader('x-amz-copy-source-if-unmodified-since', formattedDateString );
        req.setHeader('x-amz-copy-source-if-modified-since', formattedDateString );
        req.setHeader('Content-Length', '332876');
        req.setHeader('Date', formattedDateString);
        req.setHeader('Content-Type' ,'pdf');
        string auth;
        String stringToSign = method+'\n\n'+'docx'+'\n'+formattedDateString+'\n/DestinationBucket/DestinationObject';
        Blob mac = Crypto.generateMac('HMACSHA1', blob.valueof(stringToSign),blob.valueof(secret));
        String sig = EncodingUtil.base64Encode(mac);
        auth = 'AWS' + ' ' + key + ':' + sig;
            //Execute web service call
            try {
                HTTPResponse res = http.send(req);
                System.debug('REKHA-Resp:' + String.ValueOF(res.getBody()));
            } catch(System.CalloutException e) {
                system.debug(' AWS Service Callout Exception on : ERROR: ' + e.getMessage());
rekha sharmarekha sharma
In addition to above query where can i get the information if the AWS support for API is available or not

i am trying to call it through Salesforce but every time it is failing.
I saw it mentioned at amazon documentation but at below references link the APIs are available SOAP support over HTTP is deprecated, but it is still available over HTTPS. New Amazon S3 features will not be supported for SOAP. We recommend that you use either the REST API or the AWS SDKs.
refernces link :
SOAP API LINK : http://docs.aws.amazon.com/AmazonS3/latest/API/SOAPCopyObject.html 
REST API LINK : http://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectCOPY.html
Doug (Wenchang) LiuDoug (Wenchang) Liu
Hi Rekha,

I have met the similar problem as you, my error message is "SignatureDoesNotMatch" as following:

<Error><Code>SignatureDoesNotMatch</Code><Message>The request signature we calculated does not match the signature you provided. Check your key and signing method.</Message>

I want to ask if you found any solution for this problem? I'll be very appreciate if you post your solution here.

Have a nice day!

Best regards,