New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@smallwins/lambda

Package Overview
Dependencies
Maintainers
5
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@smallwins/lambda - npm Package Compare versions

Comparing version 4.20.0 to 4.21.0

2

package.json
{
"name": "@smallwins/lambda",
"version": "4.20.0",
"version": "4.21.0",
"description": "Author your AWS Lambda functions as node style errbacks.",

@@ -5,0 +5,0 @@ "main": "index",

@@ -5,3 +5,3 @@ [ ![Codeship Status for smallwins/lambda](https://codeship.com/projects/2e4082e0-d808-0133-2035-1eae90b9310e/status?branch=master)](https://codeship.com/projects/143109)

## :raised_hands::seedling: @smallwins/lambda λ
## @smallwins/lambda :seedling::raised_hands:λ

@@ -43,5 +43,5 @@ - Author your AWS Lambda functions as pure node style callbacks (aka errbacks)

A huge amount of vanilla Lambda code is working around quirky parameter validation. API Gateway gives you control over the parameters you can expect but this still means one or more of: headers, querystring paramters, form body, or url parameters. Event source style Lambdasare not much better because you still get different payloads depending on the source. In the example above we are validating *one* query string parameter `x`. Imagine a big payload! 😮
A huge amount of vanilla AWS Lambda code is working around quirky parameter validation. API Gateway gives you control over the parameters you can expect but this still means one or more of: headers, querystring, form body, or url parameters. Event source style lambdas are not much better because you can often still get differing payloads from different origin sources. In the example above we are validating *one* querystring parameter `x`. Imagine a big payload! 😮
Worse still, writing a good program we want to use JavaScript's builtin `Error` but it still needs manual serialization (and you still lose the stack trace). The latter part of this vanilla code uses the funky AWS `context` object.
Worse still, writing a good program we want to use JavaScript's builtin `Error` but it still needs manual serialization (and you still lose the stack trace). The latter part of this vanilla code uses the funky AWS `context` object.

@@ -147,3 +147,3 @@ We can do better:

A handler looks something like this
A handler looks something like this:

@@ -160,3 +160,3 @@ ```javascript

Good error handling makes programs easier to maintain. [This is a great guide digging in more.](https://www.joyent.com/developers/node/design/errors). When using `@smallwins/lambda` always use `Error` type as the first parameter to the callback:
Good error handling makes programs easier to maintain. [This is a great guide digging in more.](https://www.joyent.com/developers/node/design/errors) When using `@smallwins/lambda` always use `Error` type as the first parameter to the callback:

@@ -180,3 +180,3 @@ ```javascript

`@smallwins/lambda` serializes errors into Slack RPC style JSON. Easier to work from API Gateway:
`@smallwins/lambda` serializes errors into Slack RPC style JSON. Easier to work with from API Gateway:

@@ -193,3 +193,3 @@ ```javascript

#### <kbd>#! scripting api</kbd> :memo:
#### <kbd>#! automatations</kbd> :memo:

@@ -206,3 +206,3 @@ `@smallwins/lambda` includes some helpful automation code perfect for npm scripts. If you have a project that looks like this:

| | |-test.js
| | '-package.json :point_left: name property should equal the deployed lambda name
| | '-package.json <--- name property should equal the deployed lambda name
| |-login/

@@ -231,15 +231,46 @@ | '-logout/

Note: these scripts assume each lambda has it's own nested `package.json` file with a `name` property that matches the lambda name.
You get:
- :point_right: <kbd>npm run create src/lambdas/forgot</kbd> creates a new lambda
- :point_right: <kbd>npm run list</kbd> lists all deployed lambdas
- :point_right: <kbd>npm run deploy src/lambdas/signup brian</kbd> deploys the lambda with the alias `brian`
- :point_right: <kbd>npm run invoke src/lambdas/login brian '{"email":"b@brian.io", "pswd":"..."}'</kbd> to remote invoke a deployed lambda
- :point_right: <kbd>npm run local src/lambdas/login brian '{"email":"b@brian.io", "pswd":"..."}'</kbd> to locally invoke a lambda
- :point_right: <kbd>npm run deps src/lambdas/*</kbd> for a report of all your lambda deps
- :point_right: <kbd>npm run log src/lambdas/logout</kbd> to view the cloudwatch invocation logs for that lambda (remote run `console.log` statements show up here)
#### :fast_forward: npm run scripts :running::dash:
The `./scripts/invoke.js` is also a module and can be useful for testing.
This is :key:! Staying in the flow with your terminal by reducing hunts for information in the AWS Console. :shipit::chart_with_upwards_trend:
- :point_right: <kbd>npm run <b>create</b> src/lambdas/forgot</kbd> creates a new lambda named `forgot` at `src/lambdas/forgot`
- :point_right: <kbd>npm run <b>list</b></kbd> lists all deployed lambdas and all their alias@versions
- :point_right: <kbd>npm run <b>deploy</b> src/lambdas/signup brian</kbd> deploys the lambda with the alias `brian`
- :point_right: <kbd>npm run <b>invoke</b> src/lambdas/login brian '{"email":"b@brian.io", "pswd":"..."}'</kbd> to remote invoke a deployed lambda
- :point_right: <kbd>npm run <b>local</b> src/lambdas/login brian '{"email":"b@brian.io", "pswd":"..."}'</kbd> to locally invoke a lambda
- :point_right: <kbd>npm run <b>deps</b> src/lambdas/*</kbd> for a report of all your lambda deps
- :point_right: <kbd>npm run <b>log</b> src/lambdas/logout</kbd> to view the cloudwatch invocation logs for that lambda (remote `console.log` statements show up here)
_Note: these scripts assume each lambda has it's own nested `package.json` file with a `name` property that matches the lambda name._
### testing :white_check_mark:
You can invoke a Lambda locally with a mock payload using `lambda.local`. Say you have this lambda function:
```javascript
// always-ok.js
var lambda = require('@smallwins/lambda')
function fakeFn(event, callback) {
callback(null, Object.assign({hello:'world'}, event))
}
exports.handler = lambda(fakeFn)
```
You can imagine the test:
```javascript
// always-test.js
var fn = require('./always-ok').handler
lambda.local(fn, {fake:'payload'}, console.log)
// logs {hello:'world', fake:'payload', ok:true}
```
`./scripts/invoke.js` is also a module and can be useful for testing. It will remotely invoke your lambda.
```javascript
var invoke = require('@smallwins/lambda/scripts/invoke')

@@ -252,2 +283,1 @@

Of course you can also mock invoke a Lambda locally with `lambda.local`.
#!/usr/bin/env node
var aws = require('aws-sdk')
var async = require('async')
var region = process.argv[4] || 'us-east-1'
var region = process.env.AWS_REGION || 'us-east-1'
var lambda = new aws.Lambda({region:region})

@@ -13,5 +13,5 @@ var chalk = require('chalk')

var join = require('path').join
//
//
// usage
//
//
// npm run deploy path/to/function alias

@@ -105,3 +105,3 @@ //

if (notfound) {
callback(null, false)
callback(null, false)
}

@@ -126,3 +126,3 @@ else {

},
FunctionName: package.json.name,
FunctionName: package.json.name,
Handler: 'index.handler',

@@ -150,3 +150,3 @@ Role: package.json.lambda.role,

var params = {
FunctionName: package.json.name,
FunctionName: package.json.name,
Publish: true,

@@ -163,8 +163,8 @@ ZipFile: zipfile

}
})
})
},
function createAlias(version, callback) {
var params = {
FunctionName: package.json.name,
FunctionVersion: version,
FunctionName: package.json.name,
FunctionVersion: version,
Name: alias

@@ -205,3 +205,3 @@ }

})
},
},
function cleanupZip(callback) {

@@ -208,0 +208,0 @@ rimraf(zip)

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc