Reputation: 951
Alright,
So I'm aware of the AWS PHP SDK. I do not want to use it to make a curl call to invoke a lambda function.
I've found things about using API Gateway. I also do not want to use API Gateway. I just want to be like:
$endPoint = "https://urltoinvokethefunction"
$ch = curl_init();
$chOptions = [
CURLOPT_URL => $endPoint,
//credentials, headers, etc etc
];
curl_setopt_array($ch, $chOptions);
$result = curl_exec($ch);
Is this at all possible? I want it to be as simple as possible, just a straight curl call to invoke the function. As far as I understand it's what is happening in the SDK anyway, so it must be possible without using the SDK.
I know the most sensible way would be to use the SDK, and I have used it successfully before. I'm up against an unfortunate scenario of trying to add in custom business logic to an outdated, spider web of a CMS, and where the SDK is already included in a plugin I can't simply reuse the already namespaced SDK in a custom function.
tldr; writing a publish_post hook in Wordpress, can't use the AWS SDK because a plugin is already using it, just looking to make a straight curl call to invoke the function, not going to use API Gateway, how to?
****** UPDATE ******
Solved my problem, hanging head low... the reason I couldn't use the already loaded SDK was a versioning issue... d'oh. Stuck using a super old version for the time being, but it works.
The question still remains though, because I'm a stickler for simplicity, and I'd rather just know how to do it myself rather than import a super huge library (sledgehammer to hammer a nail kind of thing). Curious to hear a solution!
Upvotes: 1
Views: 2218
Reputation: 781
$data = array(‘key’=>'key1');
$data_string = json_encode($data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"ENTER_YOUR_PUBLIC_URL");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, “POST”);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
‘Content-Type: application/json’,
‘Content-Length: ‘ . strlen($data_string))
);
$result = curl_exec($ch);
Upvotes: 1
Reputation:
Using AWS API Gateway is dead simple to link it to your Lambda function. You simply create a resource and stage, associate it to your Lambda function, and then deploy the API. From there, you'll receive a public URL to send requests to that will execute your Lambda function.
To my knowledge, this is the only way to execute a Lambda function over HTTP(S)
Upvotes: 1