Coder Social home page Coder Social logo

serverless's Introduction

Serverless on AWS

Setup AWS CLI (Windows)

The AWS CLI is an open source tool built on top of the AWS SDK for Python that provides commands for interacting with AWS services. Once set up, you can use the CLI to access all the functionality provided on the AWS Management Console to access AWS services and configure resources.

  1. Download it. 64 Bit / 32 Bit
  2. Install it.
  3. Get your AWS Access Key ID and Secret Access Key from IAM
  4. Run aws configure

Setup Serverless Framework

  1. Download and Install it npm install -g serverless
  2. Run serverless create --template aws-nodejs --path /path/to/project --name functionName If you faced the error script execution disabled
    1. Open Powershell as Run as administrator
    2. Run Set-ExecutionPolicy RemoteSigned

You should have the below 3 files autogenerated . ├── .npmignore ├── handler.js └── serverless.yml

Writing code

1. serverless.yml

service: getOrders frameworkVersion: '2'

provider: name: aws runtime: nodejs12.x lambdaHashingVersion: 20201221 stage: prod region: us-east-1 apiName: GetOrders memorySize: 256 # Overwrite the default memory size. Default is 1024 timeout: 10

functions: getOrders: handler: index.getOrders events: - http: /orders cors: true method: get

2. index.js

'use strict'; const express = require('express') , serverless = require('serverless-http') , ordersRouter = require('./orders/orders.router');

const app = express() app.use(express.urlencoded({ extended: true })) app.use(express.json())

app.use('/', ordersRouter);

app.use('*', (req, res) => { res.status(404) res.send("Resource not found") })

const handler = serverless(app);

module.exports.getOrders = async (event, context) => { return await handler(event, context); };

3. Write your routers in the respective folders

serverless's People

Contributors

itsdevbrat avatar

Watchers

James Cloos 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.