Skip to content

Commit

Permalink
IoT support (#63)
Browse files Browse the repository at this point in the history
* Fix unsecure dependencies

* Replace eslint by standard

* Update serverless version

* Add SQS support to README and provide examples

* Update dependencies

* Add IoT support

* Add integration tests

* Add unit tests

* Add Github templates

* Add husky hooks

* Adjust travis node versions to match Lambda runtimes
  • Loading branch information
davidgf committed Jul 28, 2019
1 parent 1e8dce8 commit 5f0c612
Show file tree
Hide file tree
Showing 38 changed files with 6,847 additions and 1,911 deletions.
15 changes: 0 additions & 15 deletions .eslintrc

This file was deleted.

28 changes: 28 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
(Thanks for reporting an issue! Please, then fill out the blanks below.)

What are the steps to reproduce this issue?
-------------------------------------------
1.
2.
3.

What happens?
-------------

What were you expecting to happen?
----------------------------------

Any logs, error output, etc?
----------------------------
(If it’s long, please paste to https://pastebin.com/ and insert the link here.)


Any other comments?
-------------------

What versions of software are you using?
----------------------------------------

24 changes: 24 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
## Proposed changes

Describe the big picture of your changes here to communicate to the maintainers why we should accept this pull request. If it fixes a bug or resolves a feature request, be sure to link to that issue.

## Types of changes

What types of changes does your code introduce to the plugin?
_Put an `x` in the boxes that apply_

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)

## Checklist

_Put an `x` in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code._

- [ ] Lint and unit tests pass locally with my changes
- [ ] I have added tests that prove my fix is effective or that my feature works
- [ ] I have added necessary documentation (if appropriate)

## Further comments

If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc...
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ node_modules
.serverless_plugins
mappings.json
serverless-plugin-canary-deployments*.tgz
.vscode
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ before_install:

matrix:
include:
- node_js: '6.2'
- node_js: '8.9'
- node_js: '9.4'
- node_js: '8.10'
- node_js: '10.15'

cache:
directories:
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ You can see a working example in the [example folder](./example/).
- `Linear10PercentEvery2Minutes`: shifts 10 percent of traffic every two minutes until all traffic is shifted.
- `Linear10PercentEvery3Minutes`: shifts 10 percent of traffic every three minutes until all traffic is shifted.
- `Linear10PercentEvery10Minutes`: shifts 10 percent of traffic every 10 minutes until all traffic is shifted.
- `AllAtOnce`: shifts all the traffic to the new version, useful when you only need to execute the validation hooks.
* `alias`: (required) name that will be used to create the Lambda function alias.
* `preTrafficHook`: (optional) validation Lambda function that runs before traffic shifting. It must use te CodeDeploy SDK to notify about this step's success or failure (more info [here](https://docs.aws.amazon.com/codedeploy/latest/userguide/reference-appspec-file-structure-hooks.html)).
* `postTrafficHook`: (optional) validation Lambda function that runs after traffic shifting. It must use te CodeDeploy SDK to notify about this step's success or failure (more info [here](https://docs.aws.amazon.com/codedeploy/latest/userguide/reference-appspec-file-structure-hooks.html))
Expand Down Expand Up @@ -109,7 +110,7 @@ The plugin relies on the [AWS Lambda traffic shifting feature](https://docs.aws.
For now, the plugin only works with Lambda functions invoked by

* API Gateway
* Stream based (such as the triggered by Kinesis or DynamoDB Streams)
* Stream based (such as the triggered by Kinesis, DynamoDB Streams or SQS)
* SNS based events
* S3 events
* CloudWatch Scheduled events
Expand Down
10 changes: 5 additions & 5 deletions example/handler.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
module.exports.hello = (event, context, callback) => {
if ((event.queryStringParameters || {}).error) callback(new Error('Oh no!'));
console.log('The first version');
if ((event.queryStringParameters || {}).error) callback(new Error('Oh no!'))
console.log('The first version')
const response = {
statusCode: 200,
body: JSON.stringify({
message: 'The first version'
})
};
return callback(null, response);
};
}
return callback(null, response)
}
40 changes: 20 additions & 20 deletions example/hooks.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
const aws = require('aws-sdk');
const codedeploy = new aws.CodeDeploy({apiVersion: '2014-10-06'});
const aws = require('aws-sdk')
const codedeploy = new aws.CodeDeploy({ apiVersion: '2014-10-06' })

module.exports.pre = (event, context, callback) => {
var deploymentId = event.DeploymentId;
var lifecycleEventHookExecutionId = event.LifecycleEventHookExecutionId;
var deploymentId = event.DeploymentId
var lifecycleEventHookExecutionId = event.LifecycleEventHookExecutionId

console.log('Check some stuff before shifting traffic...');
console.log('Check some stuff before shifting traffic...')

var params = {
deploymentId: deploymentId,
lifecycleEventHookExecutionId: lifecycleEventHookExecutionId,
status: 'Succeeded' // status can be 'Succeeded' or 'Failed'
};
deploymentId: deploymentId,
lifecycleEventHookExecutionId: lifecycleEventHookExecutionId,
status: 'Succeeded' // status can be 'Succeeded' or 'Failed'
}

return codedeploy.putLifecycleEventHookExecutionStatus(params).promise()
.then(data => callback(null, 'Validation test succeeded'))
.catch(err => callback('Validation test failed'));
};
.catch(() => callback(new Error('Validation test failed')))
}

module.exports.post = (event, context, callback) => {
var deploymentId = event.DeploymentId;
var lifecycleEventHookExecutionId = event.LifecycleEventHookExecutionId;
var deploymentId = event.DeploymentId
var lifecycleEventHookExecutionId = event.LifecycleEventHookExecutionId

console.log('Check some stuff after shifting traffic...');
console.log('Check some stuff after shifting traffic...')

var params = {
deploymentId: deploymentId,
lifecycleEventHookExecutionId: lifecycleEventHookExecutionId,
status: 'Succeeded' // status can be 'Succeeded' or 'Failed'
};
deploymentId: deploymentId,
lifecycleEventHookExecutionId: lifecycleEventHookExecutionId,
status: 'Succeeded' // status can be 'Succeeded' or 'Failed'
}

return codedeploy.putLifecycleEventHookExecutionStatus(params).promise()
.then(data => callback(null, 'Validation test succeeded'))
.catch(err => callback('Validation test failed'));
};
.catch(() => callback(new Error('Validation test failed')))
}
Loading

0 comments on commit 5f0c612

Please sign in to comment.