Giter Site home page Giter Site logo

danilop / portable-serverless-app Goto Github PK

View Code? Open in Web Editor NEW
15.0 5.0 5.0 23 KB

An example of portable serverless app that can run on multiple platforms.

License: Apache License 2.0

JavaScript 100.00%
serverless aws-sam aws-lambda amazon-api-gateway amazon-sqs docker containers

portable-serverless-app's Introduction

Portable Serverless App

An example of portable serverless app that can run on multiple platforms.

The core business logic (a simple "Hello World" application in this case) is isolated from the adapters required for running on:

.
├── LICENSE                     <-- Apache License 2.0
├── README.md                   <-- This instructions file
├── src                         <-- Source code for the app
│   ├── Greetings.js            <-- "Hello World" business logic
│   ├── adapterAPI.js           <-- AWS Lambda handler for Amazon API Gateway
│   ├── adapterSQS.js           <-- AWS Lambda handler for Amazon SQS
│   ├── app.js                  <-- Express web app
│   ├── package.json            <-- NodeJS dependencies
│   └── test                    <-- Tests
│       ├── test_Greetings.js   <-- Testing business logic
│       ├── test_API.js         <-- Testing API Gateway adapter
│       ├── test_SQS.js         <-- Testing SQS adapter
│       └── test_app.js         <-- Testing web app
└── template.yaml               <-- SAM template
└── Dockerfile                  <-- To deploy web app in a container

Made with ❤️ by Danilo Poccia. Available on the AWS Serverless Application Repository.

Local execution

To run the wep app locally:

cd src/
npm install
npm start

Try the local execution using the following URLs (assuming default port 3000):

Serverless deployment

Deploy using AWS SAM, choose an S3 bucket (and optionally a prefix) to host the package of the app:

aws cloudformation package --s3-bucket <BUCKET> --s3-prefix <PREFIX> --template-file template.yaml --output-template-file packaged.yaml
aws cloudformation deploy --template-file packaged.yaml --stack-name PortableServerlessApp --capabilities CAPABILITY_IAM
aws cloudformation describe-stacks --stack-name PortableServerlessApp

The URL of the API is in the response of describe-stack in Stacks -> Outputs.

Try the plain URL or with a name adding at the end of the API Gateway endpoint: ?name=Your%20Name

Container deployment

Build and run the container locally using the following commands:

docker build -t not-so-serverless .
docker run -p 33000:3000 -d not-so-serverless

Try the local container using the following URLs (assuming port 33000):

Testing

Some tests are focused on the business logic, other on the integration with AWS Lambda or other platforms. The separation of concerns between business logic and adapters improves the testability of the solution.

To run automated tests:

cd src/
npm test

portable-serverless-app's People

Contributors

danilop avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

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