July 03, 2019
In parts 1-3 of our blog series we walked you through all of the steps of setting up your own AWS Lambda-like FaaS with Knative. All that's left now is triggering our function, so let's begin!
Using API Gateway as our example trigger makes things much easier, and hopefully you can learn about the eventing mechanism of Knative. For now, though, let's just update our API Gateway endpoint to point to our Load Balancer with the Host header, in the same way we executed it, instead of in it's existing destination (the Lambda function). In order to do so, open up Amazon API Gateway in your AWS Console and travel to the API that is attached to your Lambda function. In my case it is named
python-runtime-playground-API and it's sub-resource is
/python-runtime-playground, so let's head to the "Resources" tab of our API (on the left), then choose the
ANY section under our sub-resource, then click on
Integration Request, which is now set to
Type: LAMBDA_PROXY. In the opened window, we'll set the Integration type from
Lambda function to
HTTP, tick Use HTTP Proxy Integration, and set the Endpoint URL to our Load Balancer address.
In my previous example, it was:
OK on the new prompt. Our new integration request is now set. The page will be refreshed and 3 more sections will be added to it. This is where we add our "Host" header, like in our previous curl execution. So, open up the HTTP Headers section press Add Header, and insert a header with the
Name value to
Host and the
Mapped from value to
lambda-simple-http.default.justlikelambda.nuweba.com (The apostrophe is important so APIGW treats it as a constant value), check it out in the following GIF:
Updating our Integration Request headers to point to the function service in our Knative cluster
Then, once updated, you can use the
TEST button in the previous screen on AWS console, or just deploy the API and make the "production URL" access our cluster instead of the previous Lambda function on AWS!
If you're using the TEST widget on AWS, select a GET request and add the
track=true parameter in the Query Strings section so we can see the counter increase again.
I know it feels weird but you made it! You've just created a Lambda-like FaaS platform, that can connect to any AWS service and get triggers from API Gateway. If you think about it for a second - this thing could run most of your web app. Isn't that exciting?! Even if not - I'm proud of you. I really am.
*By the way, the Knative setup comes with Elasticsearch & Kibana logging already, so if you want to learn some more by yourselves, feel free to read around, I swear it is way more simple than you think!
It's been a long series of articles. But I'm sure that if you're passionate about serverless workloads, containers, orchestration and learning new technology stack, you've made quite the progress, or at least I hope you did.
I would have loved to attach a bit more content for those who are interested in understanding the differences between the AWS Lambda environment and the Knative one, but most importantly I would like to thank you very much for taking the time to read this article. Feel free to reach me privately (Twitter @thisiseyal) or our team at Nuweba (Twitter @nuweba_hq) if you have any questions or if you're interested in learning more about serverless platforms. We would love to hear your opinion and get your feedback! I hope this article is just the first of many more to come, whether it comes from us directly, or the serverless and Knative community.