Code Monkey home page Code Monkey logo

basiclambda's Introduction

BasicLambda

A basic example of an AWS Lambda function written in Purescript.

AWS Lambda expects a multi-parameter handler. We implemented a small handler in javascript that calls immediately into our Purescript handler.

The first argument to the handler is the event data. This is a javascript object. We define a data type to contain the data we expect. We handle the data as a Foreign. This allows us to enjoy a measure of type safety when processing data.

The second argument is a context object, which contains the succeed and fail callbacks. We use FFI to write succeed and fail functions that we can use to trigger these callbacks. We define LAMBDA effects to represent the side effects of calling this context methods.

This just demonstrates one way that we could create a Lambda function using Purescript. There are some limitations with this implementation.

The Context does not have any type guarantees. If you swap the order of the arguments in index.js, you will get a runtime error. To take full advantage of the type system, we would also need to treat Context as a Foreign type.

We did not do anything asynchronous in this example. A more realistic example would call out to an external service. An S3 event example might be more instructive.

Build and Install

To create your own Lambda package:

$> git clone https://github.com/kofno/BasicLambda
$> cd BasicLambda
$> pulp dep install
$> npm run build
$> npm run package

To install, upload the deploy.zip file as your own Lambda function.

basiclambda's People

Contributors

cwmyers avatar kofno avatar

Watchers

 avatar  avatar  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.