Skip to content

Commit 44028ba

Browse files
committed
added serverless-offline plugin
1 parent 67ad5ff commit 44028ba

File tree

7 files changed

+40
-48
lines changed

7 files changed

+40
-48
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
[![serverless](http://public.serverless.com/badges/v3.svg)](http://www.serverless.com)
22

3-
# serverless-elasticache
4-
> A simple serverless function using elasticache (redis)
3+
# aws-node-elasticache-redis
4+
> A set of serverless functions using elasticache (redis)
55
66
---
77

88
### Getting Started
99

1010
In order to install and run this example you need an AWS accounts credentials configured with your system. To get started with AWS account configuration, please follow this [link](https://serverless.com/framework/docs/providers/aws/guide/credentials/)
1111

12-
1. Clone serverless-elasticache and install npm packages
12+
1. Clone aws-node-elasticache-redis and install npm packages
1313
```
14-
git clone git@github.com:ankkho/serverless-elasticache.git
15-
cd serverless-elasticache
14+
git clone git@github.com:ankkho/aws-node-elasticache-redis.git
15+
cd aws-node-elasticache-redis
1616
npm install
1717
```
1818

handler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
const lib = require('./lib');
22

33
exports.handler = (event, context) =>
4-
lib.getAllProductsResponse(event, (error, response) => context.done(error, response));
4+
lib.getProductDataResponse(event, (error, response) => context.done(error, response));

lib/functions/getAllProducts.js renamed to lib/functions/getProductData.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const util = require('../util');
33

44
const get = function* (productId) {
55
const keyName = util.keyName(productId);
6-
return yield redis.hmgetallAsync(keyName);
6+
yield redis.hmgetallAsync(keyName);
77
};
88

99
module.exports = { get };

lib/functions/saveProductData.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const redis = require('../../aws/redis');
2+
const util = require('../util');
3+
4+
const get = function* (productId) {
5+
const keyName = util.keyName(productId);
6+
const value = JSON.parse(event.body);
7+
yield redis.hmsetAsync(keyName, value);
8+
};
9+
10+
module.exports = { get };

lib/index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
const getAllProducts = require('./getAllProducts');
1+
const getProductData = require('./getProductData');
22

33
// response for getAllProducts
4-
const getAllProductsResponse = (event, cb) => {
4+
const getProductDataResponse = (event, cb) => {
5+
console.log(event);
6+
};
7+
8+
const saveProductDataResponse = (event, cb) => {
59

610
};
711

812
module.exports = {
913
getAllProductsResponse,
14+
saveProductDataResponse,
1015
};

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"eslint": "^3.19.0",
3535
"eslint-config-airbnb-base": "11.2.0",
3636
"eslint-plugin-angular": "^3.0.0",
37-
"eslint-plugin-import": "2.7.0"
37+
"eslint-plugin-import": "2.7.0",
38+
"serverless-offline": "^3.15.0"
3839
}
3940
}

serverless.yml

Lines changed: 14 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,22 @@
1-
service: products
1+
service: product
22

33
provider:
44
name: aws
5-
runtime: nodejs4.3
5+
runtime: nodejs6.10
66

7-
# you can overwrite defaults here
8-
# stage: dev
9-
# region: us-east-1
10-
11-
# you can add statements to the Lambda function's IAM Role here
12-
# iamRoleStatements:
13-
# - Effect: "Allow"
14-
# Action:
15-
# - "s3:ListBucket"
16-
# Resource: { "Fn::Join" : ["", ["arn:aws:s3:::", { "Ref" : "ServerlessDeploymentBucket" } ] ] }
17-
# - Effect: "Allow"
18-
# Action:
19-
# - "s3:PutObject"
20-
# Resource:
21-
# Fn::Join:
22-
# - ""
23-
# - - "arn:aws:s3:::"
24-
# - "Ref" : "ServerlessDeploymentBucket"
25-
# - "/*"
26-
27-
# you can define service wide environment variables here
28-
# environment:
29-
# variable1: value1
30-
31-
# you can add packaging information here
32-
#package:
33-
# include:
34-
# - include-me.js
35-
# - include-me-dir/**
36-
# exclude:
37-
# - exclude-me.js
38-
# - exclude-me-dir/**
7+
plugins:
8+
- serverless-offline
399

4010
functions:
41-
getAllProducts:
42-
handler: handler.getAllProducts
11+
getProductData:
12+
handler: handler.getProductData
13+
events:
14+
- http:
15+
path: product/data/:id
16+
method: GET
17+
saveProductData:
18+
handler: handler.saveProductData
4319
events:
4420
- http:
45-
path: products/getAllProducts
46-
method: get
21+
path: product/save
22+
method: POST

0 commit comments

Comments
 (0)