0

trying to soap request from lambda handler but getting Cannot read properties of undefined (reading 'create')

below is my lambda handler

'use strict';
const soap = require('soap');
module.exports.handler = async (event, context) => {

    const url = 'http://www.thomas-bayer.com/axis2/services/BLZService?wsdl';
    process.env.NODE_TLS_REJECT_UNAUTHORIZED = 0
    const client = await soap.createClientAsync(url)

    console.log(client)

    return {
      statusCode: 200,
      message: 'It works!'
    }
}

Error

2022-10-18T17:49:49.403Z        5cace584-2e89-4cb2-99d0-b8b7ba7991a6    ERROR   Invoke Error    {"errorType":"TypeError","errorMessage":"Cannot read properties of undefined (reading 'create')","stack":["TypeError: Cannot read properties of undefined (reading 'create')","    at new HttpClient (/var/task/node_modules/soap/lib/http.js:40:59)","    at Object.open_wsdl (/var/task/node_modules/soap/lib/wsdl/index.js:1270:48)","    at openWsdl (/var/task/node_modules/soap/lib/soap.js:70:16)","    at /var/task/node_modules/soap/lib/soap.js:48:13","    at _requestWSDL (/var/task/node_modules/soap/lib/soap.js:76:9)","    at createClient (/var/task/node_modules/soap/lib/soap.js:94:5)","    at /var/task/node_modules/soap/lib/soap.js:104:9","    at new Promise (<anonymous>)","    at Object.createClientAsync (/var/task/node_modules/soap/lib/soap.js:103:12)","    at Runtime.module.exports.handler (/var/task/soap.js:7:31)"]}

Using soap npm module, not sure where i am going wrong, need your help.

  • Does your lambda have access to the internet? What node version is your lambda running with? – Josh Oct 18 '22 at 18:33
  • @Josh, yes do have internet access and node version is nodejs16.x – A N Pradeep Oct 19 '22 at 04:53
  • What version of the soap library? Does it work on your machine when running locally? – Josh Oct 19 '22 at 16:32
  • How do you know your lambda has internet access? Did you explicitly configure it? Did you test it? It looks to me like it is failing to open the wsdl which to me sounds like a connection issue. Your code works fine locally for me. – Josh Oct 19 '22 at 16:45
  • @Josh, i am new to lambda. i did configure my yaml file and i am trying to test the lamda in local by running sam local start-api. If you also tested the above lambda locally. can you please share me your code or steps. so that i can cross check once. – A N Pradeep Oct 19 '22 at 17:41
  • @Josh, using "soap": "^0.45.0". – A N Pradeep Oct 19 '22 at 17:43
  • Is your lambda bounded to a VPC? If so then you need to take some steps to give it internet access. If not it should have access. You can follow this to give it access ti the internet while in your VPC. https://stackoverflow.com/a/55267891/5991705 – Josh Oct 20 '22 at 21:49
  • To make sure it isn't an issue specific to soap then try to make a normal HTTP get request. if it works then that should prove you have proper internet access from your lambda. You should be able to follow steps here to make a get request. https://bobbyhadz.com/blog/aws-lambda-http-request-nodejs#make-an-http-get-request-in-a-nodejs-lambda – Josh Oct 20 '22 at 21:52

0 Answers0