是的,AWS Lambda支持使用Diagram / Graphviz生成图表以及将其保存为图片。以下是一个示例代码:
import os import subprocess
def lambda_handler(event, context): graph = "digraph { A -> B }" # This is just an example graph cmd = ["dot", "-T", "png"] p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = p.communicate(graph.encode()) with open('/tmp/graph.png', 'wb') as f: f.write(out) # Upload the image to S3 or send it as a response # ...
在该示例代码中,我们使用Python标准库中的subprocess模块调用Graphviz的dot程序,生成PNG格式的图表并将其保存在/tmp/graph.png中。您可以根据您的需求调整这个示例代码,例如将图表存储在AWS S3中,或将其作为响应直接发送回前端。