使用 AWS lambda、Zeep 和 IRESS 创建 REST API

问题描述

在以下代码中,我使用 SOAP API 创建 IRESS 会话。我能够在 jupyter 上运行它时创建会话,但在 AWS Lambda 中运行它时遇到问题。由于 API Gateway 中的时间限制为 29 秒,我在使用 API Gateway 触发它时收到 API gateway Timed Out 错误

from zeep import Client,Settings
from decimal import Decimal
import sys
import logging
import os
import time
import sys
import click
import distutils.util
import uuid
from zeep import Client
from zeep.cache import sqliteCache
from zeep.transports import Transport
from lxml import etree
import operator
import json
from random import seed
from random import random
iressMethodList = "AlertCreate,AlertGet,AlertDelete"
username2 ="testuser2"
username  = "testuser"
password ="testpassword"
endpoint =  "https://webservicestesta.iress.com.au/v4/"
companyname = "company"
iosname = 'iosname'
service_ios='IOSPLUS'
service_iresss='IRESS'
service_ips='IPS';srv = 'IPSCACHE'
app_id = str(random())
settings = Settings(strict = False,xml_huge_tree = True)
WSDL_IOS_GENERIC='http://webservices.iress.com.au/v4/wsdl.aspx?un={username}&cp={companyname}&svc=IOSPLUS&svr=cache9&pw={password}'
WSDL_IRESS_GENERIC='https://webservices.iress.com.au/v4/wsdl.aspx?un={username}&cp={companyname}&pw={password}&svc=IRESS&svr=cache9'
WSDL_IOS_URL = WSDL_IOS_GENERIC.format(companyname=companyname,username=username,password=password)
WSDL_IRESS_URL = WSDL_IRESS_GENERIC.format(companyname=companyname,password=password)
# Create the Web Services client objects,one for the IOS+ WSDL and one for the IRESS WSDL
iosPlusClient = Client(WSDL_IOS_URL,settings=settings)#,transport=transport2)
iressClient = Client(WSDL_IRESS_URL,transport=transport1)
iosPlusClientFactory = iosPlusClient.type_factory('ns0')
iressClientFactory = iressClient.type_factory('ns0')
#create the connection and key
iressSessionStartResponse = iosPlusClient.service.IRESSSessionStart(iosPlusClientFactory.IRESSSessionStartInput(Header=iosPlusClientFactory.IRESSSessionStartInputHeader(Updates=False),Parameters=iosPlusClientFactory.IRESSSessionStartInputParameters(SessionNumberToKick=-1,ApplicationID=app_id,UserName=username,CompanyName=companyname,Password=password)))
iressSessionKey = iressSessionStartResponse.Result.DaTarows.DaTarow[0].IRESSSessionKey
serviceSessionStartResponse = iosPlusClient.service.ServiceSessionStart(iosPlusClientFactory.ServiceSessionStartInput(Parameters=iosPlusClientFactory.ServiceSessionStartInputParameters(IRESSSessionKey=iressSessionKey,Service= "IOSPLUS",Server=iosname)))
serviceSessionKey = serviceSessionStartResponse.Result.DaTarows.DaTarow[0].ServiceSessionKey

在第一部分中,我想调用将触发 AWS Lambda 函数的 API 网关以创建 IRESS 会话并将 serviceSessionKey 和 iressSessionKey 以及所使用的对象(iosPlusClient、iressClient、iosPlusClientFactory、iressClientFactory)存储在 S3 存储桶中在上述功能中,以便我也可以在其他功能中使用它们。 在下一部分中,我想创建具有以下代码的帐户:

account = iosPlusClientFactory.AccountGetInput(
    Header={
        'ServiceSessionKey': serviceSessionKey,},Parameters={
    }
)
account_detail = iosPlusClient.service.AccountGet(account)

这里我需要 serviceSessionKey 和 iosPlusClientFactory ,我将它们存储在第一个函数中。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)