Giter Club home page Giter Club logo

qr-code-lambda's Introduction

qr-code-lambda

An AWS Lambda that generates a QR code for a URL. This code uses the ZXing library that, while officially in maintenance mode, is still updated and works.

Building

To build, simply run

mvn clean package

This will create target/qr-code-lambda-1.0.jar that can be deployed to AWS Lambda via the console or CLI. Note that this code does not include any deployment mechanisms - that's up to you.

Interaction

The code exposes a single "service" that is used to request a QR code. The request is a simple JSON body:

 {
     "url": "https%3A%2F%2Fwww.blah.com%2F%3Fparam1%3Dblech%26param2%3Dboo", 
     "size": 200
 }

Note that the URL is expected to be URL encoded. This prevents anything that might be in the URL from being interpreted as valid JSON.

The size parameter is optional. By default, the code returns a QR code that is 200 x 200 pixels. You can override this in the deployment environment by setting the environment variable DEFAULT_SIZE in the Lambda runtime environment. The value in the JSON takes precedence over either the default or the environment variable.

The code limits you to between 50 and 1000 pixels for the QR code. Anything outside of this range returns a 400 error.

A image/png is returned inside a APIGatewayProxyResponseEvent so that API Gateway can convert the returned data to an image.

Deployment Notes

This code doesn't require much memory and will trivially run in the default 15 second Lambda timeout. Because it is Java based I'd encourage you to use SnapStart. In my testing this code takes about 700ms to run the first time and, without SnapStart, can periodically still take that amount of time. With SnapStart it is usually around 7 to 10ms.

There is no security built into this Lambda. I've deployed behind an API Gateway with a JWT authorizer, but it should not be put out for the world without some kind of protection.

QR Code Size

Note that, depending on the length of your URL, the returned QR code can be fairly simple or extremely dense. For example, a simple request that has the URL of https://www.google.com/ looks like this:

Google QR

However, a URL that is large (this one is a bit over 2000 characters) can result in a QR code like:

Example QR

While the first QR code is easily read at 200 x 200 px, the second one may not be, depending on the screen and resolution that it is displayed with. If you have very long URL's, consider a link shortening service to create the QR code so that it is easily readable across devices.

qr-code-lambda's People

Contributors

sdunbar-wrs avatar stdunbar avatar

Watchers

 avatar

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.