Amazon Lambda Call Error

I need to call the Amazon Lambda function, from php, but I get weird edits when AWSLambdaFullAccess is present. My code is:

$client = LambdaClient::factory(array(
'key' => 'AKI...G',
'secret' => 'VXD...YOse',
'region' => 'us-west-2'
));
$result = $client->invokeAsync(array(
'FunctionName' => 'arn:aws:lambda:us-west-2:180...52:function:fe...st',
'InvokeArgs' => json_encode($array),
));

This is mistake:

User: arn:aws:iam::69...67:user/developer is not authorized to 
perform: lambda:InvokeFunction on resource: 
arn:aws:lambda:us-west-2:180...52:function:fe...st

Any ideas? Thanks

+4
source share
1 answer

You must give your PHP code permission to call your lambda function (otherwise everyone can call your code ...).

You need to create a role with the correct permission and make sure that your PHP code assumes this role (for example, with Cognito or EC2 roles).

The role should include something like:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "Stmt1234567890",
            "Effect": "Allow",
            "Action": [
                "lambda:InvokeFunction"
            ],
            "Resource": [
                "arn:aws:lambda:us-west-2:<YOUR-ACOUNT-ID>:function:<YOUR-FUNCTION-NAME>"
            ]
        }
    ]
}
+5
source

All Articles