Code Monkey home page Code Monkey logo

serverless-nba-scores's Introduction

My first serverless application

I'm an avid NBA fan so part of my day (especially during the playoffs) is devoted to avoiding any mention of last night's NBA scores. One of the big problems associated with this is waiting to watch a game and then it being a blowout by 20, 30 points. Those games are way too boring and generally not worth watching.

I saw a talk on AWS Lambda at the AWS Loft in London and wanted to try it out so I built this small serverless app. The architecture looks a bit like:

  • Route 53 for DNS Management of wasitclose.co.uk ($0.50 / month)
  • S3 for hosting the static site ($0.03 / month)
  • API Gateway to provide an endpoint for Lambda (Free for first million requests)
  • Lambda to do the actual logic to fetch the scores ($0.000001 / 100ms execution time)
  • DynamoDB to cache the responses (~$1.00 / month )

Sure I could have used heroku + node and it would have been free but I can think of a lot of small use cases for Lambda so I wanted to learn more about it.

The app is incredibly simple but it was still remarkably easy to set up and get all these tools working together. API Gateway, Lambda and Dynamodb are all managed by Cloudformation whereas the rest is currently manually managed.

To get this up and running I used the Serverless Framework - https://github.com/serverless/serverless. This does a lot of the heavy lifting for you, particularly in relation to the cloudformation stuff, and the documentation is great.

If you want to understand how Serverless applications work I would start with the Serverless Starter repo or Serverless GraphQL, or poke around in this repo.

The code that is actually executed in the lambda is in https://github.com/Ianfeather/serverless-nba-scores/blob/master/nba-scores/restApi/lib/index.js

The end result is at http://wasitclose.co.uk.

Notes to self

Deploy serverless

AWS_DEV_PROFILE=personal serverless deploy will list and deploy the lambda and gateway

Upload a new index.html

aws s3 cp --region eu-west-1 --profile personal static/index.html s3://wasitclose.co.uk/index.html

A date with games for testing

http://wasitclose.co.uk/?date=20160429

serverless-nba-scores's People

Contributors

ianfeather avatar

Stargazers

 avatar Constantin Câmpean avatar Alex Pate avatar chee avatar Giuseppe avatar

Watchers

James Cloos avatar Constantin Câmpean 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.