A helper framework to write your serverless application configuration file
npm install sls-helperA framework to implement serverless framework config file with ease and standarized resources.
sh
npm install sls-helper
`Usage
`js
// serverless.jsconst { 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.helperNameThe 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
$3
Used to implement a bucket with blocked public access
| Option | Type | Description | Attributes | Default value |
|--------|------|-------------|------------|---------------|
| resourceName | string | The logical name of the bucket | Required | |
| name | string | The bucket name | Required | |
| acl | string | The bucket acl | | Private |
| cors | boolean \| object \| array | The bucket CORS configuration. If set to
true, default configuration is set (every origin, every header) | | |
| cors.id, cors[].id | string | The CORS rule ID | | |
| cors.origin, cors[].origin | array \| string \| boolean | The CORS rule origin(s) (if value is true, it's set as every origin) | | |
| cors.methods, cors[].methods | array \| string | The CORS rule method(s) | | |
| cors.headers, cors[].headers | array \| string | The CORS rule headers(s) | | |
| cors.exposedHeaders, cors[].exposedHeaders | array \| string | The CORS rule exposed headers(s) | | |
| cors.maxAge, cors[].maxAge | number | The CORS rule max age | | |
| tags | object | A key-value object of tags to associate to the bucket | | |
| rawProps | object | Extra raw properties | See the official documentation | |#### Example
`js
const { helper } = require('sls-helper');module.exports = helper({
hooks: [
['bucket', {
resourceName: 'ServiceBucket',
name: 'my-bucket'
}]
]
});
`$3
_(since 1.2.0)_
Used to implement an IAM Role statement for your service
| Option | Type | Description | Attributes | Default value |
|--------|------|-------------|------------|---------------|
| effect | string | The IAM statement effect | Enum('Allow', 'Deny') |
'Allow' |
| action | string \| array\ | The IAM statement action | Required | |
| resource | string \| array\ | The IAM statement resource | Required | |#### Example
`js
const { helper } = require('sls-helper');module.exports = helper({
hooks: [
['iamStatement', {
action: [
's3:PutObject',
's3:GetObject'
],
resource: 'arn:aws:s3:::my-bucket/*'
}]
]
});
`$3
Used to implement Lambda Proxy APIs
| Option | Type | Description | Attributes | Default value |
|--------|------|-------------|------------|---------------|
| functionName | string | The function name | Required | |
| handler | string | The function handler | Required | |
| description | string | The function description | | |
| path | string | The API path | Required | |
| method | string | The API HTTP method | Required | |
| useApiKey | boolean | Whether the API requires API key or not | | false |
| queryParameters | object | A key value to map query string parameters to a boolean indicating if it's required or not | | |
| requestHeaders | object | A key value to map headers to a boolean indicating if it's required or not | | |
| authorizer | string | The authorizer config | See the official documentation | |
| cors | object \| boolean | See the official documentation | | |
| async | boolean | Whether the API will execute as an async lambda or not | | false |
#### Example
`js
const { helper } = require('sls-helper');module.exports = helper({
hooks: [
['apiLambdaProxy', {
functionName: 'MyFunctionName',
handler: 'path/to/my.handler',
path: '/hello-world',
method: 'get'
}]
]
});
`$3
_(since 1.1.0)_
Used to implement Lambda Functions
| Option | Type | Description | Attributes | Default value |
|--------|------|-------------|------------|---------------|
| functionName | string | The function name | Required | |
| handler | string | The function handler | Required | |
| description | string | The function description | | |
| events | array[object] | The function events | | |
| layers | array[object] | An array of function-level layers. This will override any provider-level layers _(since 1.14.0)_ | | |
| addLayers | array[object] | An array of function-level layers. This will be appended to any provider-level layers _(since 1.14.0)_ | | |
| timeout | number | The function timeout | | |
| memorySize | number | The function memorySize in MB _(since 1.10.0)_ | | |
| reservedConcurrency | number | Reserved concurrency limit for the function. By default, AWS uses account concurrency limit _(since 1.11.0)_ | | |
| package.include | array[string] | The List of paths of files to include | | |
| url | boolean | Set as
true to create a Lambda URL resource | | false |
| rawProperties | object | Raw properties to be setup in the function configuration object | | |#### Example
`js
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
}
}]
]
});
`$3
_(since 1.3.0)_
Used to implement environment variables
Configuration options are the environment variables key-value object
#### Example
`js
const { helper } = require('sls-helper');module.exports = helper({
hooks: [
['envVars', {
MY_VAR: 'and the value',
SOME_OTHER_VAR: 'and some other value'
}]
]
});
`$3
_(since 1.8.0)_
Used to implement custom resources
| Option | Type | Description | Attributes | Default value |
|--------|------|-------------|------------|---------------|
| name | string | The resource logical name | Required | |
| resource | object | The resource configuration object for Cloudformation | Required | |
#### Example
`js
const { helper } = require('sls-helper');module.exports = helper({
hooks: [
['resource', {
name: 'MyQueue',
resource: {
Type: 'AWS::SQS::Queue',
Properties: {
QueueName: 'my-super-queue'
}
}
}]
]
});
``