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
mysteriousauramysteriousaura 

Apex Callout timed out during POST to amazon aws in the sandbox testing env

Hello,

I have a apex callout to POST a list of contact records to a amazon aws server. We are testing it in the test environment but I get a Callout error: System.CalloutException: Read timed out - error. Can someone help me?

Here is the code:


        HttpRequest req = new HttpRequest();
        HttpResponse res = new HttpResponse();
        Http http = new Http();

     
        req.setEndpoint('callout:EndPoint/process');
        req.setMethod('POST');
        req.setHeader('Content-Type', 'application/json');
        req.setBody(gen.getAsString());
        //req.setBody(test);
        
        req.setCompressed(false); // otherwise we hit a limit of 32000
        
       System.debug('Post Complete');

        try {
            if(!Test.isRunningTest()) 
            {
                res = http.send(req);
                    
            } 
            
        } 
        catch(System.CalloutException e) {
            System.debug('Callout error: '+ e);
            System.debug(res.toString());
        }
        System.debug('Post response' + res.getBody());

End point is a named credential - http://xxx-xxxx-zcx-1454.us-east-1.elb.amazonaws.com:2322

Would really appreciate some help. It is my first time writing a callout!
Andy BoettcherAndy Boettcher

If you're sending a lot of data - you may want to break this thing up into smaller chunks via BATCH Apex.  Your comment of "otherwise we hit a limit of 32000" makes me think that it's just taking too darned long to send the data.  Your AWS sandbox also probably is a lower-powered instance so it would take longer to process that data anyways.

Otherwise, you can increase the callout timeout, but I'd do the BATCH route to be more "best practice" about it.  =)

Check this out:  http://salesforce.stackexchange.com/questions/46364/how-to-set-timeout-for-web-service-call

mysteriousauramysteriousaura
Thanks Andy!
I am not sending a lot of data. It is triggered when a new record is created in the contact object manually.
 I tried
req.setTimeout(20000);
but I am getting the same error. Any other ideas or should I increase Timeout?

Thanks
Jyoti
Andy BoettcherAndy Boettcher
Is there perhaps something in your sandbox that isn't working right?  Can you submit a payload to your sandbox outside of Salesforce to eliminate that possibility?
mysteriousauramysteriousaura
Hi Andy,

I used a REST client and it works fine. I was working with a load balance URL and was getting the above error.

I tried to use the URL of the actual box and now I am getting:

System.HttpResponse[Status=Forbidden, StatusCode=403]
The following error was encountered while trying to retrieve the URL: <a href="http://10.101.7.105:8384/process">http://10.101.7.105:8384/process</a></p>
<p><b>Access Denied.</b></p>
Access control configuration prevents your request from being allowed at this time. Please contact your service provider if you feel this is incorrect.</p>
Generated Mon, 24 Aug 2015 14:25:44 GMT by proxy-chi.net.salesforce.com (squid)</p>

Any idea?
Andy BoettcherAndy Boettcher
That error looks to be perhaps your Amazon server being locked down to what IPs it responds to.  The "403 Forbidden" message you are seeing is Salesforce being actively blocked by the Amazon end.
Andy BoettcherAndy Boettcher
WAIT!  I just saw the IP address - 10.x.x.x.  That's an internal non-routable address.  You need to get the public IP of that Amazon server to connect.  Remember - Salesforce is coming from the Internet.  =)
mysteriousauramysteriousaura
I have also tried with "http://elb-dpwiz-zcx-1454896069.us-east-1.elb.amazonaws.com:8384/process"
This one fails with Callout error: System.CalloutException: Read timed out - System.HttpResponse[Status=null, StatusCode=0]

I really appreciate your help on this!
Andy BoettcherAndy Boettcher
Hmmm - seems weird that you can hit this right from a REST client but cannot from Salesforce.  Something is bugging me that this may be a firewall/access control thing still.

Can you see any logs on the Amazon side that may give a hint to what's happening when Salesforce attempts to connect?  Are you administering the AWS instance or do you have a team doing that for you?
mysteriousauramysteriousaura
Hi Andy,

I got it working. Apparently some security configurations on the AWS end. I dont have the details of what exactly needed to be configured.

Thanks for your help :)
Andy BoettcherAndy Boettcher
Bingo!  Sounds great - happy coding!!  =)

Anytime!