Skip to content

Instantly share code, notes, and snippets.

@robinvdvleuten
Last active September 6, 2024 13:19
Show Gist options
  • Save robinvdvleuten/e7259939267ad3eb1dfdc20a344cc94a to your computer and use it in GitHub Desktop.
Save robinvdvleuten/e7259939267ad3eb1dfdc20a344cc94a to your computer and use it in GitHub Desktop.
Invoke sample Lambda function through PHP
<?php
require_once __DIR__.'/vendor/autoload.php';
use Aws\Lambda\LambdaClient;
$client = LambdaClient::factory([
'version' => 'latest',
// The region where you have created your Lambda
'region' => 'eu-west-1',
]);
$result = $client->invoke([
// The name your created Lamda function
'FunctionName' => 'hello-world',
]);
echo json_decode((string) $result->get('Payload'));
// You'll now see "Hello, World! in your output"
@techlab
Copy link

techlab commented Jun 10, 2019

Thank you for the code. Here is an example with credentials.

$client = LambdaClient::factory([
    'version' => 'latest',
    'region'  => 'eu-west-1',
    'credentials' => [
        'key'    => 'YOUR_AWS_ACCESS_KEY_ID',
        'secret' => 'YOUR_AWS_SECRET_ACCESS_KEY',
     ]
]);

$result = $client->invoke([
    // The name your created Lamda function
    'FunctionName' => 'hello-world',
]);

var_dump($result->get('Payload'));

@oluwapaso
Copy link

Hi, how do i invoke this asynchronously?

@nitish1986
Copy link

@oluwapaso

Hi, how do i invoke this asynchronously?

You can simply call $result = $client->invokeAsync([.....])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment