java - 如何在我的 java lambda 函数中包含和使用命令行工具?
问题描述
我正在尝试使用命令行工具(Tarql)进行一些数据转换。我不确定如何在我的部署包中包含命令行工具。我正在考虑将它保存在 tmp 文件夹中,以便我可以通过 ProcessBuilder 使用它,但我不知道如何将它包含在我的部署包中。
我面临的另一个问题是我不知道如何将文件从 s3 存储桶保存到 tmp 文件夹。
到目前为止我的代码:
public class LambdaTarqlExecution implements RequestHandler<S3Event, String> {
private static Logger log = LoggerFactory.getLogger(LambdaTarqlExecution.class);
private AmazonS3 s3 = AmazonS3ClientBuilder.standard().build();
public LambdaTarqlExecution() {
}
// Test purpose only.
LambdaTarqlExecution(AmazonS3 s3) {
this.s3 = s3;
}
@Override
public String handleRequest(S3Event event, Context context) {
context.getLogger().log("Received event: " + event);
// Get the object from the event and show its content type
S3EventNotification.S3EventNotificationRecord record=event.getRecords().get(0);
String bucket = record.getS3().getBucket().getName();
try {
ObjectMetadata object1 = s3.getObject(new GetObjectRequest(bucket, "GeoMappings.sparql"),new File("/tmp/"));
ObjectMetadata object2 = s3.getObject(new GetObjectRequest(bucket, "Countries.csv"),new File("/tmp/"));
String[] command;
ProcessBuilder pb = new ProcessBuilder("/tmp/tarql.bat", "--write-base", "--base","ontologies.se.com/Procurment", "/tmp/GeoMappings.sparql", "/tmp/Countries.csv", ">", "/tmp/geo.ttl");
PutObjectResult result = s3.putObject("turtleFiles", "geo.ttl", "/tmp/geo.ttl");
} catch (AmazonServiceException e) {
// The call was transmitted successfully, but Amazon S3 couldn't process
// it, so it returned an error response.
e.printStackTrace();
} catch (SdkClientException e) {
// Amazon S3 couldn't be contacted for a response, or the client
// couldn't parse the response from Amazon S3.
e.printStackTrace();
}
return "sucess";
}
}
解决方案
推荐阅读
- angular - 如何在 Angular 6 中使用 RecordRTC 录制屏幕
- java - 如何制作一个 android 应用程序来阅读特定的来自网站也需要登录
- post - 如何通过发布请求发送大量参数
- python - 使用 pandas 提取嵌套 json 的标题
- git - Git 功能分支从开发问题合并到暂存
- single-sign-on - 作为 SSO 解决方案的 CAS 与 Okta 与 Keycloak 的比较
- python - python raspberry pi桌面应用程序中框架/面板内的视频播放器
- xamarin - 有没有办法使用渲染器更改 Xamarin 中 iOS 开关的轮廓颜色?
- python - 预测逻辑回归时出错
- mongodb - $dateFromString 无法识别的参数:onError MongoDB 3.6