serverless / serverless/examples

Deploy API Gateway NodeJS + MongoDB

Open
#161 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
11.5k
Forks
4.4k
Avg merge
2h 55m
Merged PRs (30d)
3

Description

I have a similar scenario as the example AWS Node REST API + MongoDB.

The main difference of my project is that I wrote the service in multiple files using modules for better testability.

I can package and deploy from my Mac, but I'm implementing some CI/CD using Bitbucket Pipelines for my project. And as I use bcrypt for password generation and user authentication I need to use a docker image for bitbucket-pipelines that mimics the AWS AMI used for AWS Lambda deploys.

The main problem is that when I use the serverless deploy on the Linux machine, the command returns an error in the Bitbucket Pipelines:

Serverless Error ---------------------------------------
 
An error occurred while provisioning your stack: UserAuthLambdaFunction
    - Unzipped size must be smaller than 262144000 bytes.
 
Stack Trace --------------------------------------------

An example of my setup is the following:

Files and folders:

__tests__/ # jest folder for model and services test
bitbucket-pipelines.yml
config/
models/
package.json
serverless.yml
services/
userService.js
yarn.lock

My serverless.yml file is setup as this:

service: <NAME-OF-MY-SERVICE>

provider:
  name: aws
  runtime: nodejs6.10
  profile: ${env:AWS_PROFILE}
  stage: ${env:STAGE_ENVIRONMENT}
  region: us-east-2

functions:
  userSignup:
    handler: userService.signup
    events:
      - http:
          path: users
          method: post
  userAuth:
    handler: userService.auth
    events:
      - http:
          path: users/sign_in
          method: post

package:
  exclude:
    - .git/**
    - .gitignore
    - __tests__/**
    - config/utils.js
    - bitbucket-pipelines.yml
    - yarn.lock

My userService.js handler file is setup as this:

'use strict'

const mongoose = require('./config/mongoose')
require('dotenv').config()
let db = mongoose.connect(process.env.MONGO_URL)

const UserService = require('./services/users')
const userService = new UserService()

module.exports.signup = (event, context, cb) => {
  userService.signup(event, (err, res) => {
    cb(err, res)
    db.disconnect()
  })
}

module.exports.auth = (event, context, cb) => {
  const response = {
    statusCode: 200,
    body: {
      message: 'userService auth endpoint',
      payload: event.body
    }
  }

  cb(null, response)
  db.disconnect()
}

My service currently only does the signup part and return an authorization token as the response body. I need to know how the Mac deploys successfully (but with error from native modules as bcrypt being generated with the different architecture needed), and the Linux (AWS AMI) one can't deploy.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with bitbucket-pipelines.yml and serverless.yml, then compare the files included in the Mac and Linux deployment packages, especially native bcrypt dependencies and the listed package exclusions. Reproduce the serverless deploy in Bitbucket Pipelines and determine why the Linux package exceeds the 262144000-byte limit; done means the deployment succeeds without the package-size error.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, javascript, mongodb, nodejs
Domain
backend, ci-cd, cloud, databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.