pemre / serverless-example

This repo contains a very basic Express app to be deployed on AWS Lambda automatically by Serverless Framework.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

🌩️ Serverless example: Node.js app with Express

This repo contains a very basic Express app to be deployed on AWS Lambda automatically by Serverless Framework.

It only exposes two endpoints that respond "Hello World!".

It also has "serverless-offline" plugin for offline local development:

$ npm start

> serverless-example-node-express-app@1.0.0 start
> sls offline start

Starting Offline at stage production (eu-central-1)

Offline [http for lambda] listening on http://localhost:3002
Function names exposed for local invocation by aws-sdk:
           * app: serverless-example-production-app

   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
   β”‚                                                                       β”‚
   β”‚   ANY | http://localhost:3000/production                              β”‚
   β”‚   POST | http://localhost:3000/2015-03-31/functions/app/invocations   β”‚
   β”‚   ANY | http://localhost:3000/production/{proxy*}                     β”‚
   β”‚   POST | http://localhost:3000/2015-03-31/functions/app/invocations   β”‚
   β”‚                                                                       β”‚
   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Server ready: http://localhost:3000 πŸš€

⏬ Steps to install

Install Serverless Framework

npm install -g serverless

Configure the framework

Prefix the command with sudo if you’re running this command on Linux:

sls config credentials \
--provider aws \
--key PUBLIC_KEY \
--secret SECRET_KEY

Make sure to add your IAM User's public and secret key instead of the placeholders I specified above. The user needs programmatic access and admin permissions. Here’s the official guide in the AWS docs.

You'll see this message after executing:

βœ” Profile "default" has been configured

Install this example app

Clone this Git repo and inside its folder, run:

npm install

You are ready to start development πŸŽ‰.

πŸ§‘β€πŸ’» Local development

npm start

Local app will be served on: http://localhost:3000/production/emre

πŸ“¦ Deployment

For deployment to production, run:

npm run deploy

πŸ€– Serverless Framework will handle everything for you.

About

This repo contains a very basic Express app to be deployed on AWS Lambda automatically by Serverless Framework.

License:GNU General Public License v3.0


Languages

Language:JavaScript 100.0%