8
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

AWS LambdaをPHPから発火

Last updated at Posted at 2016-06-14

AWS LambdaをPHPから実行したかった話

結論から

公式ドキュメントを見れば基本的にそんなにつまづかない。

公式ドキュメント

実際のコード (軽くマスキング)

lambda.php
<?php
use Aws\Credentials\CredentialProvider;
use Aws\Lambda\LambdaClient;
use Aws\Lambda\Exception\LambdaException;

public function call_lambda () {
    try {
        $function_name = "function_name";
        $provider = CredentialProvider::defaultProvider();
        $client = LambdaClient::factory(array(
            "region"      => "region",
            "version"     => "version",
            "credentials" => $provider,
        ));
        $result = $client->invoke(array(
            'FunctionName' => $function_name, // REQUIRED
            'InvocationType' => 'Event',
            'LogType' => 'Tail',
        ));
    } catch (LambdaException $e) {
        throw $e;
    } catch (Exception $e) {
        throw $e;
    }
}

前提条件

aws configureでcredentialsが作成されている
参考サイト
http://dev.classmethod.jp/cloud/aws-cli-credential-config/
追記: 前提条件でaws configureとか書いたけどEC2上でPHPが動いてるのであれば、
EC2にIAMROLEが当たってればできるっぽい

8
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?