Posts

Showing posts with the label Lambda

Shrinking node_modules for AWS Lambda (My First “npm shock” and a Practical Fix)

Image
I’m a newbie in Node.js and not really familiar with the whole npm ecosystem. I honestly didn’t expect that a single npm install would explode into ~10MB spread across ~30 different folders. After a few minutes of staring at it, I realized what’s actually inside those folders: not just runtime code. What shocked me Inside node_modules you get everything: README files source files tests examples docs And then the next level of madness: modules inside modules . Duplicated dependencies nested multiple levels deep (e.g. inherits , core-util-is , tedious …), even if they already exist elsewhere in the project tree. Here’s a typical example: I’m in node_modules → package bl , and there’s another node_modules folder inside it, plus test , README and other “junk”… all for a ~10KB JS file. The obvious assumption (that turned out wrong) Once I accepted the chaos, I assumed there must be a “build for production” command that would “compile” depende...

AWS API Gateway + Lambda: How to Add a “Get By ID” Resource (Path Parameter)

Image
This thing is not trivial and I couldn’t find a simple explanation. Here is the exact sequence to add a Get By ID -style path parameter like /users/{userid} in API Gateway and wire it to Lambda. Goal Turn an existing resource like /users into: /users /users/{userid} (new resource) Step-by-step Select an existing resource (e.g. users ). Click Actions and select Create Resource . In Resource Name , put the parameter name in curly braces (e.g. {userid} ). In Resource Path , you should see read-only text like /users/ and a textbox for the parameter. Enter {userid} in the textbox and click Create Resource . You should now see a new branch in your API tree: /{userid} . Select it. Click Actions → Create Method and add ANY (or the specific method you need). ...