问题的根本原因是pyuno的身份验证过程未能成功传递。在AWS Lambda中,由于运行环境的限制,无法使用套接字或命名管道与其他进程进行通信。因此,必须使用AWS Lambda提供的ExecutionContext获取PyUNO上下文。
以下是解决此问题的代码示例:
import uno
import os
import socket
def lambda_handler(event, context):
# Get pyuno context using ExecutionContext
context = uno.getComponentContext()
resolver = context.ServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", context)
client = resolver.resolve("uno:socket,host=localhost,port=2002;urp;StarOffice.ServiceManager")
ctx = client.getPropertyValue("DefaultContext")
# Perform necessary operations using pyuno
desktop = ctx.ServiceManager.createInstanceWithContext("com.sun.star.frame.Desktop", ctx)
# Return response
return {
'statusCode': 200,
'body': 'Successful'
}
在此示例中,我们使用AWS Lambda提供的 ExecutionContext 来获取PyUNO上下文。在获取上下文后,我们可以执行任何必要的操作,例如创建或打开文档等。最后,我们返回一个成功的响应。