Esempio n. 1
0
<?php

require_once dirname(__FILE__) . '/aws.phar';
use Aws\Lambda\LambdaClient;
$_ENV['IMOS_LAMBDA_FUNCTION'] = $_ENV['IMOS_LAMBDA_FUNCTION'] ?: 'exec';
$client = LambdaClient::factory(array('profile' => 'default', 'region' => $_ENV['IMOS_LAMBDA_REGION'] ?: 'ap-northeast-1', 'version' => '2015-03-31'));
function GetRequest($argv)
{
    $request = [];
    if (isset($_ENV['IMOS_LAMBDA_BUCKET'])) {
        $request['bucket'] = $_ENV['IMOS_LAMBDA_BUCKET'];
    }
    if (isset($_ENV['IMOS_LAMBDA_INPUT'])) {
        $file = $_ENV['IMOS_LAMBDA_INPUT'];
        if (!is_readable($file)) {
            fwrite(STDERR, "Input is unreadable: {$file}\n");
            return 1;
        }
        $request['input'] = file_get_contents($_ENV['IMOS_LAMBDA_INPUT']);
    }
    if (isset($_ENV['IMOS_LAMBDA_ARGUMENTS'])) {
        $request['arguments'] = $_ENV['IMOS_LAMBDA_ARGUMENTS'];
    }
    if (isset($_ENV['IMOS_LAMBDA_OBJECT'])) {
        $request['object'] = $_ENV['IMOS_LAMBDA_OBJECT'];
    }
    $arg0 = array_shift($argv);
    $command = implode(' ', $argv);
    if (trim($command) != '') {
        $request['command'] = $command;
    }