0

please help, i am trying to convert a working python code to AWS lambda python function but i am not sure to pass lambda test event in dict format.

i have tried below code .. normal python execution works fine. but when i apply it to lambda python function i am getting fault error at input string i.e., vpn

Working code

    from zeep import Client
    client = Client('http://www.holidaywebservice.com/HolidayService_v2/HolidayService2.asmx?wsdl')
    request_data = {
        'countryCode': 'Scotland',
        'year': 2018}
    print(client.service.GetHolidaysForYear(**request_data))

Not working

    def lambda_handler(event, context):
        client = Client('http://www.holidaywebservice.com/HolidayService_v2/HolidayService2.asmx?wsdl')
        result = client.service.GetHolidaysForYear(event['vpn'])
        return result

lambda test event

    {
      "vpn": {
        "countryCode": "Scotland",
        "year": 2018
        }
    }

AWS lambda error

"errorMessage": "For input string: "{'countryCode': 'Scotland', 'year': 2018}"", "errorType": "Fault",

Maria628
  • 224
  • 3
  • 19
  • I think there is format error in your json. please insert colon : between "year" and 2018 – Smit Parmar May 10 '22 at 08:04
  • hi, sorry that was a manual type mistake.. but lambda execution fails with correct JSON, – Maria628 May 10 '22 at 08:44
  • I checked on my lambda both event["vpn"] and request_data has type dict. Please try by passing `**event["vpn"]` as you pass on above code. – Smit Parmar May 10 '22 at 08:49
  • with that i am getting this error ----- "errorMessage": "Unable to marshal response: Object of type GetHolidaysForYearOperationResult is not JSON serializable", – Maria628 May 10 '22 at 08:54
  • 1
    to fix marshal error try `data=json.loads(event["vpn"])` and send **data in parameter – Smit Parmar May 10 '22 at 09:08
  • still no luck.. now i got ---- { "errorMessage": "the JSON object must be str, bytes or bytearray, not dict", "errorType": "TypeError", – Maria628 May 10 '22 at 09:45
  • You can check [this](https://stackoverflow.com/questions/42354001/json-object-must-be-str-bytes-or-bytearray-not-dict) answer. You can try with json.dumps() and then json.loads() Hope this works – Smit Parmar May 10 '22 at 10:33
  • In the working code you are passing `**request_data` which unpacks the `request_data` dict into keyword arguments, but in the failing case you're passing `event['vpn']` as a dict. – jarmod May 10 '22 at 11:33

0 Answers0