Giter Site home page Giter Site logo

tdmalone / coffee-shop-message Goto Github PK

View Code? Open in Web Editor NEW
6.0 4.0 3.0 535 KB

A little AWS Lambda function I've got hooked up to a Flic button at our fave coffee shop. Includes Terraform config for all necessary AWS resources.

License: MIT License

JavaScript 13.50% HCL 86.50%
aws lambda javascript nodejs node-js js api-gateway flic flic-buttons tm-id-au

coffee-shop-message's Introduction

Coffee Shop Message

This is a little AWS Lambda function I've got hooked up to a Flic button at my work's fave coffee shop.

Like all good cafes they open early, and sometimes close early - particularly when they've sold out of salads, or it's a quiet afternoon. So the Flic sits on their wall, and when they're about to close they tap it... a few doors down our office gets a Slack message and we know to come get our last coffees of the day!

The Flic button on the wall at The Good Food Collective

The message as seen in our coffee-specific Slack channel

Setup

To install locally:

$ yarn

As input is required to run the function, the easiest way to see it in action is to run the integration tests documented below.

Then, to install on AWS using Terraform, see infrastructure/. You can then configure a Flic button to send POST requests to your new API whenever it is pressed!

Tests

To run all tests at once:

$ yarn test

Unit Tests

To run:

$ yarn unit-tests

Note that unit tests are yet to be written, and will currently just pass!!

Integration Tests

To run:

$ yarn docker-tests

Integration tests require Docker. They run in lambci/lambda:nodejs6.10 (GitHub | Docker Hub).

The following environment variables must be defined on your system:

  • SLACK_HOOK_DEV
  • SNS_TOPIC_DEV
  • AWS_ACCESS_KEY_ID
  • AWS_SECRET_ACCESS_KEY
  • AWS_DEFAULT_REGION
  • CI - optional

The final CI variable above is optional, but recommended. If set (which it is by default on Travis CI, for instance), it will cause errors to be thrown rather than returned as an API Gateway style response. If not set, tests will still 'pass', as errors will be mapped to a HTTP status code rather than thrown.

License

MIT.

coffee-shop-message's People

Contributors

tdmalone avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

coffee-shop-message's Issues

The refactor to external Lambda response library breaks the response

Re fd2d625:

This isn't in prod/master yet, but in dev it is triggering a 'Malformed Lambda proxy response' error at API Gateway, likely because the body isn't sent as a JSON string:

{"isBase64Encoded":false,"headers":{},"statusCode":200,"body":[{"ResponseMetadata":{"RequestId":"27f2cb59-34d0-5450-a437-9811e2ee48d5"},"MessageId":"d3ecba33-56c2-59f7-b570-e97b80fca572"},"ok"]}

The other issue here though, is we lost the custom 'Message sent, thanks guys!' that goes back to the coffee shop.

It might either be worth reverting fd2d625 before merging dev into master, or looking into a way to resolve this issue while still using the external dependency to build the proxy response.

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.