Example of running TensorFlow in Lambda
Clone the repository.
git clone https://github.com/RyoWakabayashi/tensorflow-lambda.git
cd tensorflow-lambda
Install asdf plugins.
asdf plugin-add aws-sam-cli \
; asdf plugin-add direnv \
; asdf plugin-add jq \
; asdf plugin-add nodejs \
; asdf plugin-add python \
; asdf plugin-add yarn
Install Languages and Tools.
asdf install
Download MobileNet v2 model files.
python download_models.py
Move to the sam directory.
cd sam
Build sam.
Make sure Docker is launched.
sam build
$ sam local start-api
...
2022-08-01 15:12:33 * Running on http://127.0.0.1:3000/ (Press CTRL+C to quit)
Calling the API from another terminal.
curl -XPOST \
http://127.0.0.1:3000/predictions \
-H "Content-Type: image/jpeg" \
--data-binary @imgs/sample.jpg | jq
Deploy with a guide the first time.
API URL is displayed after execution.
$ sam deploy --guided
...
-------------------------------------------------------------------------------------------------------
Outputs
-------------------------------------------------------------------------------------------------------
Key Api
Description API Gateway endpoint URL for v1 stage for Tensorflow sample function
Value https://some.execute-api.ap-northeast-1.amazonaws.com/v1/predictions
-------------------------------------------------------------------------------------------------------
If you save the configuration information, you do not need to use the guide for the second time or later.
sam deploy
Change the URL to the value displayed after deployment.
curl -XPOST \
https://some.execute-api.ap-northeast-1.amazonaws.com/v1/predictions \
-H "Content-Type: image/jpeg" \
--data-binary @imgs/sample.jpg | jq
You may view the log.
sam logs --stack-name some-stack-name
Install commitlint.
yarn
Install pre-commit.
pip install --requirement requirements.txt
asdf reshim python
pre-commit install
Run pre-commit manually.
pre-commit run --all-files
No authentication is applied in this sample.
Please add authentication to the production.