Saturday, 22 April 2017

Serverless Framework with AWS Lambda error: Cannot find module "./region_config_data.json"

Just started today with server less and aws lambda. I'm trying to write a lambda to upload some objects to S3 buckets. I'm using a plugin "serverless-webpack" to use webpack and to be able to test my functions locally.

However I'm getting the following error when requesting 'aws-sdk' module in my code.

Error: Cannot find module "./region_config_data.json"
    at webpackMissingModule (/Users/paco/workspace/repo_git/dario-aws/functions/uploadFileToS3/.webpack/handler.js:18917:85)
    at Object.<anonymous> (/Users/paco/workspace/repo_git/dario-aws/functions/uploadFileToS3/.webpack/handler.js:18917:187)
    at __webpack_require__ (/Users/paco/workspace/repo_git/dario-aws/functions/uploadFileToS3/.webpack/handler.js:20:30)
    at Object.<anonymous> (/Users/paco/workspace/repo_git/dario-aws/functions/uploadFileToS3/.webpack/handler.js:18342:21)

Below the code of my handler.js:

    if (!global._babelPolyfill) {
    require('babel-polyfill')
}

var AWS=require('aws-sdk')

export const upload = (event, context, cb) => {
    const p = new Promise((resolve, reject) => {
        resolve('success')
    })
    p
        .then(r => cb(null, {
    message: 'Go Serverless Webpack (Babel) v1.0! Your function executed successfully!',
    event,
}))
        .catch(e => cb(e))
}

package.json:

{

  "name": "serverless-s3-manager",
  "version": "1.0.0",
  "description": "Serverless webpack example using Babel",
  "main": "handler.js",
  "scripts": {
    "eslint": "./node_modules/.bin/eslint *.js",
    "eslint:fix": "./node_modules/.bin/eslint *.js --fix",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "Nicola Peduzzi <thenikso@gmail.com> (http://nikso.net)",
  "license": "MIT",
  "devDependencies": {
    "babel-core": "^6.13.2",
    "babel-loader": "^6.2.4",
    "babel-plugin-transform-runtime": "^6.12.0",
    "babel-preset-es2015": "^6.13.2",
    "babel-preset-stage-0": "^6.5.0",
    "babel-polyfill": "6.13.0",
    "serverless-webpack": "^1.0.0-rc.3",
    "webpack": "^1.13.1",
    "eslint": "^3.19.0",
    "eslint-plugin-import": "^2.2.0"
  },
  "dependencies": {
    "aws-sdk": "^2.45.0",
    "babel-runtime": "6.11.6"
  }
}

web pack.config.js :

module.exports = {
    entry: './handler.js',
    target: 'node',
    module: {
        loaders: [{
            test: /\.js$/,
            loaders: ['babel'],
            include: __dirname,
            exclude: /node_modules/,
        }]
    }
}

In serverless.yml I'm specifying the was-region:

name: aws
  runtime: nodejs6.10
  apiKeys:
    - myFirstKey

# you can overwrite defaults here
  stage: dev
  region: eu-west-1

In my .aws/credentials I have specified access and secret keys. I can correctly access AWS using aws cli.

Any help? Should I create a file called "./region_config_data.json", in that case, which data do I put inside? I cannot find any info about it.

Thanks!



via fgonzalez

No comments:

Post a Comment