This sample shows how to deploy a barcode decoding service in AWS Lambda.
Warning
This tutorial is intended for beginner developers and some steps may not be best practices.
We support lambda nodejs 20 and above environments, both x64 and arm64.
-
Have nodejs installed on your local development machine.
-
An account with access to the AWS Console.
-
Know how to unzip or compress files.
-
Know how to open a terminal and use the
cdcommand.
If you don't have this sample locally, please copy the url to a browser and download it.
https://github.com/Dynamsoft/capture-vision-nodejs-samples/archive/refs/heads/main.zip
Unzip it, assuming you unzipped it to path/to/capture-vision-nodejs-samples-main.
Go into the lambda directory. Now the path is path/to/capture-vision-nodejs-samples-main/lambda.
Please visit https://www.dynamsoft.com/customer/license/trialLicense?product=dbr&package=desktop. Then replace Your license in your source code (index.js and index.mjs in lambda directory).
Open the terminal. cd to the directory.
cd path/to/capture-vision-nodejs-samples-main/lambdaInstall dependencies.
npm iIf your local development machine is not of the same OS/arch as your target lambda (linux x64/arm64), you need to force install another dependency as well.
npm i dynamsoft-capture-vision-for-node-lib-linux-<arch>@<version> -f -EYou can find <arch>@<version> in node_modules/dynamsoft-capture-vision-for-node/package.json->optionalDependencies.
We provide both index.js or index.mjs. You can choose one you like and delete another.
If your local development machine is not of the same OS/arch as lambda, it is better to remove the useless node_modules/dynamsoft-capture-vision-for-node-dylib-<your development machine's OS-arch> before deployment.
All situations apply, you can remove some files in node_modules/koffi, only leave:
node_modules/koffi/build/koffi/<target lambda os_arch>node_modules/koffi/index.jsnode_modules/koffi/package.json
Note that we used PT_READ_BARCODES_SPEED_FIRST in sample. This eliminates the need to load the AI model.
If you want to use other preset templates, you need to install dynamsoft-capture-vision-for-node-model. You can check the <version> in SDK's package.json->peerDependencies.
npm i dynamsoft-capture-vision-for-node-model@<version> -EAnd you may need to upgrade your Lambda specifications.
Compress the files in the lambda directory to lambda.zip. Do not include the root directory lambda. You can test like this: Move the lambda.zip into an empty folder, Exctract Here the lambda.zip, you will not see a directory called lambda.
Open AWS Console page in browser.
Type lambda in the search box (in left top) of AWS Console. Click the Lambda button to enter Lambda Console.
Create function -> Any function name -> Check and choose x86_64 or arm64 ->
Additional configurations -> Enable function url ->
Auth type as None -> Enable CORS ->
Click create function button and it go to a new page ->
Click upload from -> .zip file -> Choose lambda.zip that you created ->
Waiting... Until it says like "Successfully uploaded file." ->
You can see files in Code source changed; if not, refresh page -> Deploy ->
Go to Configuration tab -> General configuration -> Edit ->
Memory to 256MB, timeout to 1 min -> Function URL -> Copy URL
index.html is a front-end example. Please edit index.html that in your local development machine, replace https://<url-id>.lambda-url.<region>.on.aws/ to the Function URL you copied.
Open the index.html in a browser. Click and select an image to upload.
If everything goes well, you will see the text result.