Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sls-helper

Package Overview
Dependencies
Maintainers
0
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sls-helper

A helper framework to write your serverless application configuration file

  • 1.15.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

Serverless Helper

A framework to implement serverless framework config file with ease and standarized resources.

Installation

npm install sls-helper

Usage

// serverless.js

const { helper } = require('sls-helper');

module.exports = helper({
	hooks: [

		['bucket', {
			resourceName: 'ServiceBucket',
			name: 'my-bucket'
		}],

		'custom.myHelperWithoutConfigs'
	]
});

Plugins

In order to implement a plugin for the framework, you must publish a package with the following pattern: sls-helper-plugin-{plugin-name}.

The plugin-name must then be used as a prefix to use a helper of that plugin, for example: plugin-name.helperName

The package must export an object mapping helper names to helper implementations.

Each helper is a function that receives the following arguments:

  • serviceConfig: The current service config object
  • helperParams: The (optional) configuration for the helper.

It also has to return the new service config object.

Plugin list:

  • JANIS

Core Helpers

S3 Bucket (bucket)

Used to implement a bucket with blocked public access

OptionTypeDescriptionAttributesDefault value
resourceNamestringThe logical name of the bucketRequired
namestringThe bucket nameRequired
aclstringThe bucket aclPrivate
corsboolean | object | arrayThe bucket CORS configuration. If set to true, default configuration is set (every origin, every header)
cors.id, cors[].idstringThe CORS rule ID
cors.origin, cors[].originarray | string | booleanThe CORS rule origin(s) (if value is true, it's set as every origin)
cors.methods, cors[].methodsarray | stringThe CORS rule method(s)
cors.headers, cors[].headersarray | stringThe CORS rule headers(s)
cors.exposedHeaders, cors[].exposedHeadersarray | stringThe CORS rule exposed headers(s)
cors.maxAge, cors[].maxAgenumberThe CORS rule max age
tagsobjectA key-value object of tags to associate to the bucket
rawPropsobjectExtra raw propertiesSee the official documentation
Example
const { helper } = require('sls-helper');

module.exports = helper({
	hooks: [
		['bucket', {
			resourceName: 'ServiceBucket',
			name: 'my-bucket'
		}]
	]
});

IAM Role Statement (iamStatement)

(since 1.2.0)

Used to implement an IAM Role statement for your service

OptionTypeDescriptionAttributesDefault value
effectstringThe IAM statement effectEnum('Allow', 'Deny')'Allow'
actionstring | array<string>The IAM statement actionRequired
resourcestring | array<string>The IAM statement resourceRequired
Example
const { helper } = require('sls-helper');

module.exports = helper({
	hooks: [
		['iamStatement', {
			action: [
				's3:PutObject',
				's3:GetObject'
			],
			resource: 'arn:aws:s3:::my-bucket/*'
		}]
	]
});

API Lambda Proxy (apiLambdaProxy)

Used to implement Lambda Proxy APIs

OptionTypeDescriptionAttributesDefault value
functionNamestringThe function nameRequired
handlerstringThe function handlerRequired
descriptionstringThe function description
pathstringThe API pathRequired
methodstringThe API HTTP methodRequired
useApiKeybooleanWhether the API requires API key or notfalse
queryParametersobjectA key value to map query string parameters to a boolean indicating if it's required or not
requestHeadersobjectA key value to map headers to a boolean indicating if it's required or not
authorizerstringThe authorizer configSee the official documentation
corsobject | booleanSee the official documentation
asyncbooleanWhether the API will execute as an async lambda or notfalse
Example
const { helper } = require('sls-helper');

module.exports = helper({
	hooks: [
		['apiLambdaProxy', {
			functionName: 'MyFunctionName',
			handler: 'path/to/my.handler',
			path: '/hello-world',
			method: 'get'
		}]
	]
});

Lambda Function (function)

(since 1.1.0)

Used to implement Lambda Functions

OptionTypeDescriptionAttributesDefault value
functionNamestringThe function nameRequired
handlerstringThe function handlerRequired
descriptionstringThe function description
eventsarray[object]The function events
layersarray[object]An array of function-level layers. This will override any provider-level layers (since 1.14.0)
addLayersarray[object]An array of function-level layers. This will be appended to any provider-level layers (since 1.14.0)
timeoutnumberThe function timeout
memorySizenumberThe function memorySize in MB (since 1.10.0)
reservedConcurrencynumberReserved concurrency limit for the function. By default, AWS uses account concurrency limit (since 1.11.0)
package.includearray[string]The List of paths of files to include
urlbooleanSet as true to create a Lambda URL resourcefalse
rawPropertiesobjectRaw properties to be setup in the function configuration object
Example
const { helper } = require('sls-helper');

module.exports = helper({
	hooks: [
		['function', {
			functionName: 'MyFunctionName',
			handler: 'path/to/my.handler',
			events: [
				{
					schedule: 'rate(1 hour)',
				},
				{
					s3: {
						bucket: 'myBucket',
						event: 's3:ObjectCreated:*',
						rules: [
							{ prefix: 'somePrefix' },
							{ suffix: 'someSuffix' }
						]
					}
				}
			],
			url: true,
			rawProperties: {
				rawProperties: 1
			}
		}]
	]
});

Environment variables (envVars)

(since 1.3.0)

Used to implement environment variables

Configuration options are the environment variables key-value object

Example
const { helper } = require('sls-helper');

module.exports = helper({
	hooks: [
		['envVars', {
			MY_VAR: 'and the value',
			SOME_OTHER_VAR: 'and some other value'
		}]
	]
});

Resource (resource)

(since 1.8.0)

Used to implement custom resources

OptionTypeDescriptionAttributesDefault value
namestringThe resource logical nameRequired
resourceobjectThe resource configuration object for CloudformationRequired
Example
const { helper } = require('sls-helper');

module.exports = helper({
	hooks: [
		['resource', {
			name: 'MyQueue',
			resource: {
				Type: 'AWS::SQS::Queue',
				Properties: {
					QueueName: 'my-super-queue'
				}
			}
		}]
	]
});

Keywords

FAQs

Package last updated on 22 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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