1

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!

2
  • 1
    You would have to go through the process of signing the request to invoke the AWS API with your account credentials, which is a huge pain. It's much easier to use the SDK for that. If you want a "straight curl call" to invoke a Lambda function then API Gateway is really the only way. Commented Aug 11, 2016 at 17:30
  • Those are the two things I said I do not want to do hahahahah. I figured it would be a pain, which is why I'd like to know if someone has already done it before diving in :p Commented Aug 11, 2016 at 17:34

2 Answers 2

1
$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);
Sign up to request clarification or add additional context in comments.

Comments

1

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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.