Chapter 7. Calling functions from a client
This chapter covers
- Using a Lambda function from within a web page via JavaScript
- Invoking a Lambda function from a native mobile app
- Serving a dynamic website with AWS Lambda and Amazon API Gateway
In the previous chapter, you learned how to use standalone functions for common tasks, subscribing the functions to events or scheduling a recurring execution. You also learned how to use modules and libraries with Lambda functions. In this chapter, you’ll build on that knowledge to call Lambda functions from clients outside of AWS.
When we created our first function in chapter 2, we tested the function from the web console and invoked the function using the AWS CLI. But you can use any AWS SDK to call Lambda functions. When you build a web application, one interesting use case is to call Lambda functions as your back end, directly from the JavaScript code running in the browser of your users.
- Invoke the Lambda function directly, using the AWS Lambda API.
- Call the function through a web API that you modeled via the Amazon API Gateway.
In this section, we’ll focus on the first case, as described in figure 7.1, where the client application is JavaScript code running in a web browser.