lambda call Api soap fail System.Net.WebException

0

hi guys , i have a lambda function that call an externale Soap Api, if i launch in local all work good , but if i test in lambda i have this error:

2023-04-16T13:30:43.956Z	d405592c-2d8b-445a-a41a-7075de51104c	fail	System.Net.WebException: The operation has timed out.
   at System.Net.HttpWebRequest.GetResponse()
   at System.Net.WebClient.GetWebResponse(WebRequest request)
   at System.Net.WebClient.OpenRead(Uri address)
   at System.Net.WebClient.OpenRead(String address)
   at SoapApiCall.Function.FunctionHandler(ILambdaContext context) in C:\Users\giacomo.carcano\.aws\SoapApiCall\src\SoapApiCall\Function.cs:line 23
   at lambda_method1(Closure , Stream , ILambdaContext , Stream )
   at Amazon.Lambda.RuntimeSupport.Bootstrap.UserCodeLoader.Invoke(Stream lambdaData, ILambdaContext lambdaContext, Stream outStream) in /src/Repo/Libraries/src/Amazon.Lambda.RuntimeSupport/Bootstrap/UserCodeLoader.cs:line 145
   at Amazon.Lambda.RuntimeSupport.HandlerWrapper.<>c__DisplayClass8_0.<GetHandlerWrapper>b__0(InvocationRequest invocation) in /src/Repo/Libraries/src/Amazon.Lambda.RuntimeSupport/Bootstrap/HandlerWrapper.cs:line 55
   at Amazon.Lambda.RuntimeSupport.LambdaBootstrap.InvokeOnceAsync(CancellationToken cancellationToken) in /src/Repo/Libraries/src/Amazon.Lambda.RuntimeSupport/Bootstrap/LambdaBootstrap.cs:line 176
2023-04-16T13:30:43.956Z d405592c-2d8b-445a-a41a-7075de51104c fail System.Net.WebException: The operation has timed out. at System.Net.HttpWebRequest.GetResponse() at System.Net.WebClient.GetWebResponse(WebRequest request) at System.Net.WebClient.OpenRead(Uri address) at System.Net.WebClient.OpenRead(String address) at SoapApiCall.Function.FunctionHandler(ILambdaContext context) in C:\Users\giacomo.carcano\.aws\SoapApiCall\src\SoapApiCall\Function.cs:line 23 at lambda_method1(Closure , Stream , ILambdaContext , Stream ) at Amazon.Lambda.RuntimeSupport.Bootstrap.UserCodeLoader.Invoke(Stream lambdaData, ILambdaContext lambdaContext, Stream outStream) in /src/Repo/Libraries/src/Amazon.Lambda.RuntimeSupport/Bootstrap/UserCodeLoader.cs:line 145 at Amazon.Lambda.RuntimeSupport.HandlerWrapper.<>c__DisplayClass8_0.<GetHandlerWrapper>b__0(InvocationRequest invocation) in /src/Repo/Libraries/src/Amazon.Lambda.RuntimeSupport/Bootstrap/HandlerWrapper.cs:line 55 at Amazon.Lambda.RuntimeSupport.LambdaBootstrap.InvokeOnceAsync(CancellationToken cancellationToken) in /src/Repo/Libraries/src/Amazon.Lambda.RuntimeSupport/Bootstrap/LambdaBootstrap.cs:line 176

And this is the code that i use

using Amazon.Lambda.Core;
using System.Net;

// Assembly attribute to enable the Lambda function's JSON input to be converted into a .NET class.
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer))]

namespace SoapApiCall;

public class Function
{
    public string FunctionHandler(string sSQLQuery, ILambdaContext context)
    {
        Console.WriteLine("pippo");
        sSQLQuery = "select top 10 numero,inizio,premio from dre";
        string sAddress = "https://URL:52031/iservice.asmx/Query?";
        //Crea il web client.
        WebClient client = new WebClient();
        client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
        //Imposta le credenziali. 
        client.Credentials = new System.Net.NetworkCredential("USER", "PWD");
        //Effettua la chiamata.
        Stream data = client.OpenRead(sAddress + "SQL=" + sSQLQuery);
        client.Dispose();
        StreamReader reader = new StreamReader(data, System.Text.Encoding.UTF7);
        string sXML = reader.ReadToEnd();
        Console.WriteLine(sXML);
        return sXML;
    }
}

the function is not in a Vpc infact if i try to call a simple rest service all work Good I don't know what the problem could be.

Thanks for help

  • Is your SOAP endpoint on the public internet or is it private or firewalled location?

asked a year ago359 views
1 Answer
0

Hi,

Is the soap endpoint working if you call it externally (e.g postman)?

Since you are not in vpc, internet access for egress traffic is allowed.

profile picture
EXPERT
answered a year ago
  • Yes, i try soapui and directly from visualstudio with a simple console application and all work good. and my lambda function is not in a vpc. could amazon ip be blocked?

  • Just noticed the port. Have you allowed in the security group if lambda execution role the outbound traffic for port 52031?

  • no, I didn't authorize the port, how do I do it?

  • Actually my bad, because your lambda is not in a owned in your account (default or custom one) VPC, so my above comment on security group doesnt hold. Is this just exposed for anyone on the internet or behind you private datacenter? I am thinking whether could be some firewall on target site (NET web api) that does not allow the lambda to call it. https://repost.aws/questions/QUxB-xtH5fQPGvjZG5iS5uMA/calling-on-prem-web-api-from-aws-lambda

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions