Skip to content

brendannee/lambda-image-generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lambda Image Generator

This is a node.js function designed to be run on Amazon Lambda. It takes an Automatic trip object and returns a base64 image of a .png receipt.

An example of the receipt:

This function is available by POSTing to:

https://l88zdv2agd.execute-api.us-east-1.amazonaws.com/prod/automaticTripReceipt

For example:

curl -X POST -H "Content-Type: application/json" -H "Cache-Control: no-cache" -d '{"url":"https://api.automatic.com/trip/T_ce5fb4aa2f3ea1dc/","id":"T_ce5fb4aa2f3ea1dc","user":"https://api.automatic.com/user/U_9855dcf2030c0111/","started_at":"2015-04-06T17:34:06.704000Z","ended_at":"2015-04-06T18:53:02.322000Z","distance_m":120878.2,"duration_s":4735.6,"vehicle":"https://api.automatic.com/vehicle/C_d0411b0c53b42478/","start_location":{"lat":37.54876,"accuracy_m":10,"lon":-121.27866},"start_address":{"name":"West Side Freeway, Vernalis, CA 95385, USA","display_name":"I-5, Vernalis, CA","street_number":"Unknown","street_name":"I-5","state":"CA","city":"Vernalis","country":"US"},"end_location":{"lat":37.76704,"accuracy_m":10,"lon":-122.41697},"end_address":{"name":"1454 15th Street, San Francisco, CA 94103, USA","display_name":"15th St, SF, CA","street_number":"1454","street_name":"15th St","state":"CA","city":"SF","country":"US"},"path":"yvddFpffcVowKnqOgg@xs@gVzc@a{ArvCcrF~oKebEnaIuy@z_BuF~IaIlKwwAvaB_[ha@aFpHyBnE{ApFu@hGKhF\\\\rLzBvt@lBpb@tG~u@lG|t@h@vNZ|RZ~Or@zNjHrv@fIfz@nA`HtClIzElHrCjCdHhEzDvCrDbExEbJzB`IlAtJ^nL~@nL~DdOzSrm@vFzOvCvKpErUbAzKIvJgBrL_BtEeDfGsBjDkB|E{A~IqAvWJtJpDn[vTxhBfDzN~Vdw@zu@x`CdBbGdBlI|@bHf@pJHtJcAhp@m@xb@BzK`AjVlI|}@fB~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a_kmpl":17,"score_events":46.16,"score_speeding":-66.78,"hard_brakes":2,"hard_accels":0,"duration_over_70_s":1201,"duration_over_75_s":5,"duration_over_80_s":0,"vehicle_events":[{"lat":37.65499,"lon":-121.42847,"created_at":"2015-04-06T17:45:18Z","g_force":0.4,"type":"hard_brake"}],"start_timezone":"America/Los_Angeles","end_timezone":"America/Los_Angeles","city_fraction":0.01,"highway_fraction":0.99,"night_driving_fraction":0,"idling_time_s":null,"tags":[]}' https://l88zdv2agd.execute-api.us-east-1.amazonaws.com/prod/automaticTripReceipt

Setup

AWS Lambda needs a different version of the phantomjs binary than the one needed to run on max os. This unix binary is included in this repo.

Install dependencies:

npm install

Running locally

A script has been created that simulates the lambda environment and will allow you to test locally. This script generates the base64 formatted image, puts it inside of an HTML image tag and saves an HTML. It will then try to open it in your browser for viewing.

To run locally and generate a png image:

node local image

To run locally and generate html:

node local html

You can edit the input data that the local instance uses by editing sample-data/trip.json.

Deploying to Amazon Lambda

To build the project:

node build

Upload the resulting process.zip to AWS Lambda.

About

Takes an Automatic trip object and returns a base64 image of a .png receipt

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published