2

I wish to implement the answer that is outlined here: https://stackoverflow.com/a/50397276/1980516

However, I find that I keep running into Unable to import module 'index' at exactly this line:

const _archiver = require('archiver');

So, I'm guessing that I cannot do this via the online console. Instead, I probably have to create a deployment package.

How do I go about this? I apparently need AWS CLI, Node.js, npm and I'm new to all of it. In the Amazon docs I can't find a practical list of how to set up my local development environment.

What tools do I install, which versions and in what order exactly?

Edit: Windows :)

Diana
  • 789
  • 8
  • 34
  • What OS are you using? I can provide some more detail if I know if it's Mac, Linux, etc. – bwest Mar 05 '19 at 16:40
  • For a short quick thing, do what @noobius is suggesting i.e. zip up all your dependencies (node modules) & source (say index.js) & upload directly to Lambda using console. If the package is small (< 2MB IIRC), you can continue to edit on console. Long term, look at `AWS SAM` or `serverless` as @bwest has suggested. – asr9 Mar 05 '19 at 16:51

2 Answers2

4

My guess is that you need to npm install archiver and package the node_modules dependencies along with your index.js (handler file for your lambda entry point). You can zip up and deploy/upload it to your lambda.

Also have a look at https://github.com/serverless/serverless framework, that will do these type of things easier.

noobius
  • 1,529
  • 7
  • 14
4

Have a look at AWS SAM, the Serverless Application Model. It provides a local development setup for things like Lambda functions and API Gateway endpoints, and a way to easily package and deploy things. The exact steps you need are:

  1. Create an AWS account and an IAM user with admin privileges
  2. Install node.js
  3. Install the AWS CLI (and configure it with aws configure)
  4. Install SAM CLI and Docker (the local instances run in docker containers)
  5. Initialize a new SAM project with sam init --runtime nodejs (or other runtime version if need)
  6. Run through the quickstart to get an idea of how to define a SAM template, build a SAM app, and deploy.

If you don't want to use the framework or local development environment and just want to create the source bundle, there are docs. The gist is:

  1. Install nodejs (e.g. using homebrew or an installer)
  2. npm install the modules you need
  3. Zip up your code including the node_modules folder
  4. Upload the zip via the AWS Console
bwest
  • 9,182
  • 3
  • 28
  • 58