我正在尝试将一个drools项目(使用eclipse构建)部署到AWS Lambda上,但遇到了Lambda的一些权限问题。
首先,让我描述一下我的AWS Lambda函数和我的部署结构:
当我触发AWS Lambda时,我在尝试访问demorule / demo.xls时遇到permissions denied
错误(下面的完整堆栈跟踪)。
创建KieSession时,代码中会触发此错误:
kSession = kContainer.newKieSession("demorule");
我相信上面的代码行将excel文件解压缩到默认目录/var/task
并尝试读取它。默认情况下,AWS Lambda会限制默认目录中文件的权限。
此问题的当前解决方法涉及在/tmp
目录中创建文件。
非常感谢任何帮助/反馈,
"errorMessage": "/var/task/demorule/demo.xls (Permission denied)",
"errorType": "java.io.FileNotFoundException",
"stackTrace":
"java.io.RandomAccessFile.open0(Native Method)",
"java.io.RandomAccessFile.open(RandomAccessFile.java:316)",
"java.io.RandomAccessFile.<init>(RandomAccessFile.java:243)",
"org.apache.poi.poifs.nio.FileBackedDataSource.newSrcFile(FileBackedDataSource.java:130)",
"org.apache.poi.poifs.nio.FileBackedDataSource.<init>(FileBackedDataSource.java:46)",
"org.apache.poi.poifs.filesystem.NPOIFSFileSystem.<init>(NPOIFSFileSystem.java:218)",
"org.apache.poi.poifs.filesystem.NPOIFSFileSystem.<init>(NPOIFSFileSystem.java:166)",
"org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:278)",
"org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:250)",
"org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:229)",
"org.drools.decisiontable.parser.xls.ExcelParser.parseFile(ExcelParser.java:95)",
"org.drools.decisiontable.SpreadsheetCompiler.parseResource(SpreadsheetCompiler.java:123)",
"org.drools.decisiontable.SpreadsheetCompiler.compile(SpreadsheetCompiler.java:110)",
"org.drools.decisiontable.SpreadsheetCompiler.compile(SpreadsheetCompiler.java:83)",
"org.drools.decisiontable.DecisionTableProviderImpl.compileResource(DecisionTableProviderImpl.java:78)",
"org.drools.decisiontable.DecisionTableProviderImpl.loadFromResource(DecisionTableProviderImpl.java:44)",
"org.drools.compiler.compiler.DecisionTableFactory.loadFromResource(DecisionTableFactory.java:37)",
"org.drools.compiler.builder.impl.KnowledgeBuilderImpl.decisionTableToPackageDescr(KnowledgeBuilderImpl.java:404)",
"org.drools.compiler.builder.impl.CompositeKnowledgeBuilderImpl$12.map(CompositeKnowledgeBuilderImpl.java:437)",
"org.drools.compiler.builder.impl.CompositeKnowledgeBuilderImpl.buildResource(CompositeKnowledgeBuilderImpl.java:322)",
"org.drools.compiler.builder.impl.CompositeKnowledgeBuilderImpl.buildPackageDescr(CompositeKnowledgeBuilderImpl.java:307)",
"org.drools.compiler.builder.impl.CompositeKnowledgeBuilderImpl.buildPackages(CompositeKnowledgeBuilderImpl.java:114)",
"org.drools.compiler.builder.impl.CompositeKnowledgeBuilderImpl.build(CompositeKnowledgeBuilderImpl.java:105)",
"org.drools.compiler.kie.builder.impl.AbstractKieModule.buildKnowledgePackages(AbstractKieModule.java:243)",
"org.drools.compiler.kie.builder.impl.KieContainerImpl.createKieBase(KieContainerImpl.java:484)",
"org.drools.compiler.kie.builder.impl.KieContainerImpl.getKieBase(KieContainerImpl.java:447)",
"org.drools.compiler.kie.builder.impl.KieContainerImpl.newKieSession(KieContainerImpl.java:604)",
"org.drools.compiler.kie.builder.impl.KieContainerImpl.newKieSession(KieContainerImpl.java:575)"
答案 0 :(得分:0)
我无法使用.xls文件解决此问题,但使用.drl文件代替工作。我将.xls编译为.drl文件,然后将drools maven项目作为jar包装到我的AWS Lambda项目中。
将项目部署到AWS Lambda后,成功读取.drl文件。
答案 1 :(得分:0)
作为替代方案,您可以使用这些文件设置S3存储桶,并使用一些AWS SDK代码访问它们。我也知道你可以在/ tmp文件夹中写入和读取,如果你真的需要,但你仍然需要从S3中提取文件并将它们写入/ tmp
下的目录