Skip to content
This repository was archived by the owner on Feb 10, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ Note that the ok and lastUpdated are reserved and will automatically be populate
o ok is true when statuscode is 200, false otherwise
o lastUpdated is the date.time at which the check was ran

* healthcheck to be able to `invoke` lambdas requires the following Policy Statement in `iamRoleStatements`:
* healthcheck needs to be able to `invoke` lambdas

If your project relies on the IAM Role created by the Serverless Framework, you add the following Policy Statement in `iamRoleStatements`:

```yaml
iamRoleStatements:
Expand All @@ -88,6 +90,8 @@ iamRoleStatements:
- function:${self:service}-${opt:stage, self:provider.stage}-*
```

Alternatively, you may specify the IAM Role explicitly, which will need to allow lambda invocation (`lambda:InvokeFunction`). See options.

If using pre-check, the deployment user also needs a similar policy so it can run the healthcheck lambda.

* All done! healthcheck will run on SLS `deploy` and `package` commands
Expand All @@ -96,6 +100,7 @@ If using pre-check, the deployment user also needs a similar policy so it can ru

* **cleanFolder** (default `true`)
* **memorySize** (default `128`)
* **role** (default `undefined` – if undefined, falls back to default IAM Role generated by Serverless Framework)
* **name** (default `${service}-${stage}-healthcheck-plugin`)
* **schedule** (default `rate(5 minutes)`)
* **timeout** (default `10` seconds)
Expand All @@ -105,8 +110,9 @@ If using pre-check, the deployment user also needs a similar policy so it can ru
```yml
custom:
healthcheck:
cleanFolder: false,
cleanFolder: false
memorySize: 256
role: healthCheckHandlerRole
name: 'make-them-pop'
schedule: 'rate(15 minutes)'
timeout: 20
Expand Down
12 changes: 12 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class HealthCheck {
this.healthcheck = {
cleanFolder: true,
memorySize: 128,
role: undefined,
name: this.serverless.service.service + '-' + this.options.stage + '-healthcheck-plugin',
schedule: ['rate(5 minutes)'],
timeout: 10,
Expand All @@ -70,6 +71,11 @@ class HealthCheck {
this.healthcheck.memorySize = this.custom.healthcheck.memorySize
}

/** Role */
if (typeof this.custom.healthcheck.role === 'string') {
this.healthcheck.role = this.custom.healthcheck.role
}

/** Function name */
if (typeof this.custom.healthcheck.name === 'string') {
this.healthcheck.name = this.custom.healthcheck.name
Expand Down Expand Up @@ -211,6 +217,12 @@ class HealthCheck {
timeout: this.healthcheck.timeout
}

if (typeof this.healthcheck.role === 'string') {
this.serverless.service.functions.healthCheckPlugin.role = {
'Fn::GetAtt': [ this.healthcheck.role, 'Arn' ]
}
}

return this.serverless.service.functions.healthCheckPlugin
}

Expand Down