smisy / aws-lambda-boilerplate

aws lambda, typescript, mongodb, nodejs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AWS Lambda in TypeScript and MongoDB

serverless Build Status Codacy Badge Coverage Status

Features

Setup

npm install

Run unit tests

npm test

Build

npm run build

Start on local

npm start

Environment variable

serverless read env variables from env files. There 3 env files in project with 3 stages: local, development and production

env.local.yml
env.development.yml
env.production.yml

you should find the format file as below

env.local.yml
MONGODB_URL: mongodb://localhost:27017/aws-lambda
<variable name>: <value>
npm scripts env
npm start env.local.yml
npm run deploy env.development.yml
npm run deploy:prod env.production.yml

User Roles

You may have many roles in your project: user, moderator and admin. You may define your role policies in shared/Policies.ts

export default [
  {
    roles: ['user'],
    resources: '/users/profile',
    permissions: 'GET'
  }
];

Deploy to aws lambda services

We need aws credential to deploy our aws-lambda functions to aws services.

NOTE:

update your MONGODB_URI at env.development.yml and env.production.yml

  • Generate aws_access_key_id & aws_secret_access_key from your aws account
  • Add aws credential to your local
    $ vim  ~/.aws/credentials
    
    [your profile]
    aws_access_key_id=XXXXXXXXXXXXXX
    aws_secret_access_key=XXXXXXXXXXXXXXXXXXX
    region=us-east-1
    
  • Deploy in development: AWS_PROFILE=<your profile> npm run deploy
  • Deploy in production: AWS_PROFILE=<your profile> npm run deploy:prod

About

aws lambda, typescript, mongodb, nodejs

License:MIT License


Languages

Language:TypeScript 99.9%Language:JavaScript 0.1%