如何在AWS EMR流式集群中包含PHP所需的库


How do I include PHP required libs in an AWS EMR streaming cluster

我创建了一个PHP项目,将JSON格式转换为AVRO格式。最初的项目需要PHP库,我不知道如何添加到EMR中。

这是EMR:收到的stderr日志

PHP Warning:  require_once(vendor/autoload.php): failed to open stream: No such file or     directory in /mnt/var/lib/hadoop/tmp/nm-local-dir/usercache/hadoop/filecache/12/convert-json-to-avro.php on line 3
PHP Fatal error:  require_once(): Failed opening required 'vendor/autoload.php'   (include_path='.:/usr/share/pear:/usr/share/php') in /mnt/var/lib/hadoop/tmp/nm-local-   dir/usercache/hadoop/filecache/12/convert-json-to-avro.php on line 3
log4j:WARN No appenders could be found for logger (amazon.emr.metrics.MetricsUtil).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

这是映射器的主要代码:

#!/usr/bin/php
<?php
require_once 'vendor/autoload.php';
error_reporting(E_ALL);
ini_set('display_errors', 1);
$outputFile = __DIR__ . '/test_avro_out.avr';
$avroJsonSchema = file_get_contents(__DIR__ . '/HttpRequestEvent.avsc');
// Open $file_name for writing, using the given writer's schema
$avroWriter = AvroDataIO::open_file($outputFile, 'w', $avroJsonSchema);
$counter = 1;
while (($buf = fgets(STDIN)) !== false) {
    try {
        //replace ,null: with ,"null": to prevent map keys which are not strings.
        $original = array("null:","userIp");
        $replaceWith   = array("'"null'":", "userIP");
        $data = json_decode(str_replace($original, $replaceWith, $buf), true);
        //print_r($buf);
        if ($data === false || $data == null ) {
            throw new InvalidArgumentException("Unable to parse JSON line");
        }
        $mapped = map_request_event($data);
        var_dump($mapped);
        //$avroWriter->append($mapped);
        //echo json_encode($mapped), "'n";
    } catch (Exception $ex) {
        fprintf(STDERR, "Caught exception: %s'n", $ex->getMessage());
        fprintf(STDERR, "Line num: %s'n",$counter);
        fprintf(STDERR, "buf: %s'n", $buf);
    }
    $counter++;
}
$avroWriter->close();

请注意,我使用的是require_once 'vendor/autoload.php';,它表示autoload.php在文件夹供应商之下。

将供应商文件夹加载到电子病历集群的正确方法是什么(那里有所需的文件)?require_once路径是否应该更改?

谢谢。

根据Guy的评论,我使用了一个类似于您在这里可以找到的bash脚本。

我已经更改了代码中的require_once 'vendor/autoload.php'行,以指向我放置文件的位置。(/home/hadoop/contents运行良好)。最后,我添加了一个EMR引导程序自定义步骤,您可以在其中添加bash脚本,以便它可以在PHP流步骤之前运行。