Git Product home page Git Product logo

barcode-qr-decoder-lambda's Introduction

Banner Easily decode barcodes and QR codes at scale with AWS Lambda! With this Lambda Function you will be able to add decoding features to your applications at scale!

What do I need?

AWS Account If you don't already have an account or you have not been handed one as part of a workshop, please visit the following link!

How can I read QR codes with AWS Lambda?

Step 1. Create an Amazon S3 bucket.

  • You will need to have an Amazon S3 Bucket created.
  • You will need to create a folder inside that bucket, where you will upload your images to decode.(Optional)

CloudShell

Step 2, Generate code artifacts and dependencies

To read QR/Barcodes, we are going to be using the Zbar, an open source software suite for reading bar codes. We are going to include Zbar and other necessary packages into Lambda Layers for our Lambda function to work. But don't worry, we have already automated this process for you, in a simple script you can run in your AWS Cloudshell! Here are the steps you have to follow:

  • Access AWS CloudShell, a browser-based shell inside the AWS console. You can click the terminal icon next to the search bar or looking for Cloudshell in the service search bar.

CloudShell

  • Once CloudShell has initiallized, clone this repo

    • git clone https://github.com/aws-samples/Barcode-QR-Decoder-Lambda.git
  • Run the setup.sh script in order to generate the needed lambda layers and code package. You must specify the bucket where you want to upload this artifacts replacing <BUCKET_NAME> with the S3 bucket name you created.

    • sh Barcode-QR-Decoder-Lambda/src/code/setup.sh -b <BUCKET_NAME>
  • Once the script finishes, you should see 3 new files in your S3 bucket under BarcodeQRDecoder/qr-reader/assets/ path, the two Lambda layers containing the libraries needed (Pillow and Pyzbar) and the lambda code packaged in a .zip file

S3Files

Step 3, Create your Lambda function

  • Create a new Lambda Function.
  • Select Author from scratch.
  • Input a new name for your function
  • Select Python 3.7 as runtime
  • Select x86_64 as architecture
  • Create a new role with basic Lambda permissions
  • Replace the code with Python code inside code/lambda.py.

You have now created the Lambda function!

Step 4, Add Layers to your Lambda function

As we mentioned before, your function needs some packages to run correctly. If you completed step 2, you should have the layers artifacts ready in your bucket! Follow these steps to create your layers:

  • Open the Layers page of the Lambda console.
  • Choose Create layer.
  • Under Layer configuration, for Name, enter a name for your layer.
  • (Optional) For Description, enter a description for your layer.
  • To upload a file from Amazon S3, choose Upload a file from Amazon S3. Then, for Amazon S3 link URL, enter the S3 URI of the artifact.
  • For Compatible architectures, choose x86_64.
  • For Compatible runtimes, choose Python 3.7.
  • Choose Create.

Repeat these steps for both artifacts created in S3.

Next, go to the Lambda function and in your layers section, select Add Layer. Select your layers which will be available at the Custom AWS layers dropdown.

Step 5, Configure the permissions needed

Head over to IAM and add permissions to your associated role to access your S3 Bucket.

You can find your role in the Configuration --> Permissions tab in the function editor.

Also, increase your lambda timeout to 60 seconds in the function configuration.

Step 6, Configure your Amazon S3 Trigger event

  • Once you open your new Lambda Function, head over to the Function overview panel and click on Add trigger.

Add Event

  • Select S3 from the trigger list.
  • Select the S3 bucket where you will be uploading your files.
  • Select All object create events.
  • If you want to add prefix to specify a folder you can also add it.

Event Info

  • Once you have configured all parameters, Add the trigger.

Event Completed

Step 7, Try out your Lambda Function

You are now ready to add Barcode/QR code decoding capabilities to your applications at scale! Simply add an image with a QR to your S3 bucket folder you specified earlier. You can see the logs your lambda function returns in the CloudWatch Logs console.

Test

barcode-qr-decoder-lambda's People

Contributors

danystinson avatar alejandrogil avatar

Stargazers

Dan avatar Adrian Brown avatar

Watchers

 avatar  avatar

barcode-qr-decoder-lambda's Issues

zip error: Nothing to do!

Thanks for sharing the repo and putting in the effort!

When following the instructions and executing the setup.sh file, I receive the following error:

cli:

bash Barcode-QR-Decoder-Lambda/src/code/setup.sh -b qrscan

error message:

adding: python/lib/python3.7/site-packages/bin/read_zbar (deflated 25%)
zip warning: name not matched: Barcode-QR-Decoder-Lambda/src/code/lambda_function.zip
zip error: Nothing to do! (try: zip -r lambda_function.zip . -i Barcode-QR-Decoder-Lambda/src/code/lambda_function.zip)
upload: ./pyzbar_layer.zip to s3://moritz-qrscan/BarcodeQRDecoder/qr-reader/assets/pyzbar_layer.zip
upload: ./pillow_layer.zip to s3://moritz-qrscan/BarcodeQRDecoder/qr-reader/assets/pillow_layer.zip
rm: cannot remove ‘lambda_function.zip’: No such file or directory

due to this error, there is no lambda_function.zip in the assets folder later

how to solve this issue?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.