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
reettik mitrareettik mitra 

Unable to tunnel through proxy. Proxy returns "HTTP/1.1 503 Service Unavailable AWS S3 Storage

I have sucess fully integrated with the AWS S3 for storing data.So basically I am trying to store the csv data generated from apex and want to store in AWS bucket .
Here is my code 
public static void StoreInAWS(String csvFile){
    Document doc = new Document(Name = 'documentName', Body = 
    Blob.valueOf(csvFile),  Type = 'csv', ContentType='application/vnd.ms-excel');
    system.debug(doc);
    String key = '';//mY key
    String secret = '';//my secret
    String formattedDateString = DateTime.now().formatGMT('EEE, dd MMM yyyy 
     HH:mm:ss z');
    String filename = 'folder/' + 'DocName ';//inside the bucket I have created a folder 
    named 'folder'
    String attachmentBody = csvFile;
    system.debug(attachmentBody);
    String bucketname = 'deletedrecords';//My bucket Name
    String host = 's3-us-east-1.amazonaws.com';
    system.debug('https://' + bucketname + '.' + host + '/' + filename);
    HttpRequest req = new HttpRequest();
   
    req.setMethod('PUT');
    req.setEndpoint('https://' + bucketname + '.' + host + '/'+ filename);
    req.setHeader('Host', bucketname + '.' + host);
    req.setHeader('Content-Length', String.valueOf(attachmentBody.length()));
    req.setHeader('Content-Type', doc.ContentType);
    req.setHeader('Connection', 'keep-alive');
    req.setHeader('Date', formattedDateString);
    req.setHeader('ACL', 'public-read-write');
    req.setBodyAsBlob(doc.body);
        
   // String stringToSign = 'PUT ' + doc.ContentType + '\n' + formattedDateString + '\n' + 
       '/' + bucketname + '/' + filename;
    //String encodedStringToSign = EncodingUtil.urlEncode(stringToSign, 'UTF-8');
   // Blob mac=Crypto.generateMac('HMACSHA1',blob.valueof(stringToSign),blob.valueof(secret));
    //String signedKey  = EncodingUtil.base64Encode(mac);
   // String authHeader = 'AWS' + ' ' + key + ':' + signedKey ;
    //req.setHeader('Authorization',authHeader);
    //String decoded = EncodingUtil.urlDecode(encodedStringToSign , 'UTF-8');
    system.debug('Sending the request');
    system.debug(req);
    Http http = new Http();
    HTTPResponse res = http.send(req);
    system.debug(res);
    System.debug(res.getBody());
}

getting this error-->
"unable to tunnel through proxy http/1.1 503 service unavailable"
 
SwethaSwetha (Salesforce Developers) 
HI reettik,

This error occurs due to proxy/if you are behind a firewall.

To fix this, please ensure that your network team has whitelisted the below suggested Salesforce IP addresses
https://help.salesforce.com/articleView?id=000321501&type=1&mode=1
Ensure your third party endpoint is accessible

Similar error reported by other users:
https://developer.salesforce.com/forums/?id=9062I000000gAAyQAM
https://salesforce.stackexchange.com/questions/270947/system-calloutexception-unable-to-tunnel-through-proxy-proxy-returns-http-1-1
https://salesforce.stackexchange.com/questions/295396/unable-to-tunnel-through-proxy-proxy-returns-http-1-1-503-service-unavailable
https://developer.salesforce.com/forums/?id=9062I000000gBThQAM

Hope this helps you. Please mark this answer as best so that others facing the same issue will find this information useful. Thank you
reettik mitrareettik mitra
Hi Swetha tried with whitelisting the IP but unfortunately it didnt worked!!
I have whitelisted my IP and still the error is the same.
 
SwethaSwetha (Salesforce Developers) 
HI Reettik,
Can you double-check that all the specified IP ranges in the salesforce documentation are whitelisted at the network level? 
If yes, you will need to loop in your network team to confirm if they are seeing any incoming traffic/outgoing traffic as next step.Thanks