This is a demo that integrates Tensorflow with AWS Lambda.
- An AWS account
Once inside this example's directory, install Serephem.
$ npm i
The Serephem plugin will take care of retrieving all the TensorFlow dependencies and injecting them into the Serverless Lambdas zip artifact prior to deploying to AWS.
Make sure you configure the serverless.yml
file to your necessities before deploying (i.e. region
, stage
, profile
...)
$ sls deploy -v
Remember to run
sls remove
when finished with this demo.
This project features 2 Lambdas:
- A TensorFlow addition of two numbers
- A NumPy that prints properties of a matrix
tensorflow_test.py
It uses the TensorFlow library to add two integer numbers.
Two integer numbers a and b. The Lambda test event JSON looks as follows:
{
"a": 30,
"b": 90
}
The Lambda will add those numbers using the tf.add
function. The result looks as follows:
{
"message": "TensorFlow \"add\" function test: 30 + 90",
"result": "120"
}
The TensorFlow package includes NumPy, since it is a dependency.
numpy_test.py
Creates a 2x3 matrix of integers and returns some of its NumPy properties.
None.
{
"message": "NumPy test",
"event": {},
"attrs": {
"ndim": 2,
"itemsize": 8,
"dtype.name": "int64",
"size": 6
}
}
In case you want to use this example to locally test the Serephem plugin, you can do the following:
-
Open a new terminal window and go to the Serephem root folder
-
Run
npm link
-
Return to the terminal window for the
tensorflow-lambda
example -
Run
npm link serverless-ephemeral
-
Run
sls package -v
to see your changes