简体   繁体   中英

Python: using zeep with wsdl on S3

I'm working on a soap api for a customer.

Currently, I have both the wsdl and xsd in my git repo, all of them being packaged for a lambda function. Thisisn't very convenient and also considering lambda size limit.

I'd like to move the wsdl and xsd to an S3.

I've managed during my cicd to deploy my wsdl/xsd in the S3 and not in the lambda.

However, I'm struggling to have it working with zeep.

Currently:

    root = Path(os.path.abspath(os.path.dirname(__file__))) / 'data/in/'
    wsdl_url = f"file:///{root / wsdl_file_path / wsdl_file_name}".replace('\\', r'/')
    transport = Transport(session=self.session)
    client = Client(wsdl=wsdl_url, transport=transport)

The thing is that the wsdl_url can only be a http or a file:/// url with local references, not S3. How should I do to reference an S3 file?

I could mount the S3 but that seems very heavy for such a small need.

Thanks !

Generate a pre-signed GET URL for the assets in S3 and use those pre-signed URLs.

Your Lambda function will need permission to get the objects from S3 ( s3:GetObject on the relevant WSDL and XSD object keys). If the WSDL and XSD were public objects, which I presume they are not, then you could dispense with the pre-signed URLs and simply use public S3 URLs.

Be aware that the maxiumum lifetime of the pre-signed URLs will be at most that of the credentials used to generate them. If you need longer, then you could consider using IAM User credentials to generate them, because IAM User credentials are long-lived whereas IAM Role credentials, such as your Lambda function would be using, are short-lived.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM