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.
- Download it. 64 Bit / 32 Bit
- Install it.
- Get your AWS Access Key ID and Secret Access Key from IAM
- Run aws configure
- Download and Install it npm install -g serverless
- Run serverless create --template aws-nodejs --path /path/to/project --name functionName
If you faced the error script execution disabled
- Open Powershell as Run as administrator
- Run Set-ExecutionPolicy RemoteSigned
You should have the below 3 files autogenerated . ├── .npmignore ├── handler.js └── serverless.yml
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