This guide currently covers NodeJS on Lambda. Until the Python Blueprint is completed, please refer to our simplified guide to Webhooks using Python on Lambda.
AWS Lambda is a compute service that runs your code in response to events and automatically manages the compute resources for you, making it easy to build applications that respond quickly to new information.
Algorithmia + Lambda
Algorithmia provides a built-in AWS Lambda Node.js blueprint, making it easy to call the Algorithmia API in response to events from Amazon Kinesis, Amazon DynamoDB, Amazon S3, and other Amazon web services.
For example, you could combine several algorithms from Algorithmia to:
- Automatically generate smart thumbnails (using face detection to ensure every thumbnail is perfectly cropped)
- Take advantage of Algorithmia’s speech-to-text algorithm to transcribe videos uploaded to S3 on the fly
- You could even leverage a predictive model every time DynamoDB updates.
Algorithmia and Lambda make it easy to rapidly build and deploy serverless solutions in minutes.
Setup your Lambda function
- Navigate to the AWS Lambda console
- Pick “Blueprints”
Algorithmiainto the filter
- set an Application Name and Topic, and click “Deploy”
- wait for AWS to deploy, then click “algorithmia” under the Resources section
- click “Add Trigger” and configure as needed for your workflow
- click on the Lambda icon next to “serverless-algorithmia-YourFunctionName” at the top
- edit the code, setting
const inputDatato handle the triggering event’s datastructure (the template assumes an S3 event), and modifying the output (in
client.algo(algorithm).pipe(inputData).then((output) =>as needed for your workflow.
- for higher security, configure your KMS Encrypted Key as shown below, and set
const kmsEncryptedApiKeyin your code
- for a simpler but less secure config, you can embed your API Key directly into your code by assigning a value to
- save and test your code
apiKey to your Algorithmia API key.
Advanced authentication (more secure)
Follow these steps to encrypt your Algorithmia API Key for use in your function.
1. Create a KMS key
Follow this AWS guide to create your KMS key.
2. Give your lAWS Lambda function execution role permission for the
3. Encrypt the event collector token using the AWS CLI
4. Copy the base-64 encoded, encrypted key (CiphertextBlob) to the
See the NodeJS guide for an introduction to using the Algorithmia NodeJS client to call algorithms and manage data.
Your account can make up to 80 Algorithmia requests at the same time (this limit can be raised if needed).
See also the AWS Lambda walk through on our blog.