Skip to content

Commit

Permalink
Alias for event source mapping (davidgf#9)
Browse files Browse the repository at this point in the history
* Support stream events

* Add end-to-end tests
  • Loading branch information
davidgf committed Mar 8, 2018
1 parent 621afee commit 1025ba6
Show file tree
Hide file tree
Showing 18 changed files with 3,869 additions and 377 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
node_modules
.serverless
.serverless_plugins
mappings.json
serverless-plugin-canary-deployments*.tgz
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
example/
268 changes: 0 additions & 268 deletions cf-computed-example.json

This file was deleted.

5 changes: 2 additions & 3 deletions example/handler.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
'use strict';

module.exports.hello = (event, context, callback) => {
if ((event.queryStringParameters || {}).error) callback(new Error('Oh no!'));
console.log('The first version');
const response = {
statusCode: 200,
body: JSON.stringify({
message: 'First version',
message: 'The first version'
})
};
return callback(null, response);
Expand Down
15 changes: 11 additions & 4 deletions example/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@
"description": "",
"main": "handler.js",
"dependencies": {
"aws-sdk": "^2.203.0"
"aws-sdk": "^2.203.0",
"uuid": "^3.2.1"
},
"devDependencies": {
"serverless": "^1.26.1",
"serverless-plugin-aws-alerts": "^1.2.4",
"serverless-plugin-canary-deployments": "^0.1.0"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"package": "npm un --no-save serverless-plugin-canary-deployments && npm pack ../ && npm i --no-save serverless-plugin-canary-deployments-0.1.0.tgz && sls package -s dev",
"deploy": "npm un --no-save serverless-plugin-canary-deployments && npm pack ../ && npm i --no-save serverless-plugin-canary-deployments-0.1.0.tgz && sls deploy -s dev",
"populate-table": "node ./scripts/populate-test-table"
},
"author": "",
"license": "ISC"
Expand Down
13 changes: 13 additions & 0 deletions example/scripts/populate-test-table.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const AWS = require('aws-sdk');
const uuid = require('uuid');

const generatePutRequest = () => ({ PutRequest: { Item: { id: uuid() } } });
const putRequests = new Array(25).fill().map(() => generatePutRequest());
const params = { RequestItems: { StreamsTestTable: putRequests } };

const documentClient = new AWS.DynamoDB.DocumentClient({ region: 'us-east-1' });

documentClient.batchWrite(params, (err, data) => {
if (err) console.log(err);
else console.log(data);
});
24 changes: 24 additions & 0 deletions example/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ functions:
handler: handler.hello
events:
- http: GET hello
- stream:
type: dynamodb
arn:
Fn::GetAtt:
- StreamsTestTable
- StreamArn
alarms:
- name: foo
namespace: 'AWS/Lambda'
Expand All @@ -42,3 +48,21 @@ functions:
handler: hooks.pre
postHook:
handler: hooks.post

resources:
Resources:
StreamsTestTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: StreamsTestTable
AttributeDefinitions:
- AttributeName: id
AttributeType: S
KeySchema:
- AttributeName: id
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
StreamSpecification:
StreamViewType: NEW_AND_OLD_IMAGES
Loading

0 comments on commit 1025ba6

Please sign in to comment.