Skip to content
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
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"extends": "airbnb-base",
"env": {
"node": true
"node": true,
"mocha": true
},
"rules": {
"strict": "off",
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ serverless install -u https://github.com/serverless/examples/tree/master/folder-
| [Aws Fetch File And Store In S3](https://github.com/serverless/examples/tree/master/aws-node-fetch-file-and-store-in-s3) <br/> Fetch an image from remote source (URL) and then upload the image to a S3 bucket. | nodeJS |
| [Aws Function Compiled With Babel](https://github.com/serverless/examples/tree/master/aws-node-function-compiled-with-babel) <br/> Demonstrating how to compile all your code with Babel | nodeJS |
| [Aws Github Webhook Listener](https://github.com/serverless/examples/tree/master/aws-node-github-webhook-listener) <br/> Extend your github repositories with this github webhook listener | nodeJS |
| [Aws Node Helloworld Tested](https://github.com/serverless/examples/tree/master/aws-node-helloworld-tested) <br/> A simple example showing a http helloworld including a unit test. | nodeJS |
| [Aws Iot Event](https://github.com/serverless/examples/tree/master/aws-node-iot-event) <br/> Example on how to setup a AWS IoT Rule to send events to a Lambda function | nodeJS |
| [Aws Node Rekognition Analysis S3 Image](https://github.com/serverless/examples/tree/master/aws-node-rekognition-analysis-s3-image) <br/> Analyse an Image from an S3 Bucket with Amazon Rekognition | nodeJS |
| [Aws Node Restapi Mongodb](https://github.com/serverless/examples/tree/master/aws-node-rest-api-mongodb) <br/> Serverless REST API with MongoDB using Mongoose and Bluebird | nodeJS |
Expand Down
44 changes: 44 additions & 0 deletions aws-node-helloworld-tested/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# AWS Node Helloworld Tested

A simple example showing a http helloworld including a unit test.

## Install

$ serverless install -u https://github.com/serverless/examples/tree/master/aws-node-helloworld-tested -n helloworld

## Deploy

$ cd helloworld
$ serverless deploy
Serverless: Packaging service...
Serverless: Creating Stack...
Serverless: Checking Stack create progress...
.....
Serverless: Stack create finished...
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading artifacts...
Serverless: Uploading service .zip file to S3 (1.36 KB)...
Serverless: Updating Stack...
Serverless: Checking Stack update progress...
...............................
Serverless: Stack update finished...
Service Information
service: hellworld
stage: dev
region: us-east-1
api keys:
None
endpoints:
GET - https://<someid>.execute-api.us-east-1.amazonaws.com/dev/hello-world
functions:
helloWorld: hellworld-dev-helloWorld

## Testout endpoint

$ curl -sL $(sls info |grep -oEi 'http.*') | jq .message
"Go Serverless v1.0! Your function executed successfully!"


## Run local unit tests

npm test
13 changes: 13 additions & 0 deletions aws-node-helloworld-tested/handler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';

module.exports.helloworld = (event, context, callback) => {
const response = {
statusCode: 200,
body: JSON.stringify({
message: 'Go Serverless v1.0! Your function executed successfully!',
input: event,
}),
};

callback(null, response);
};
23 changes: 23 additions & 0 deletions aws-node-helloworld-tested/handler.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const assert = require('assert');

const hander = require('./handler');

describe('Handler', () => {
describe('#helloworld', () => {
it('should return 200 status code', (done) => {
const callback = (err, result) => {
assert.equal('200', result.statusCode);
done();
};
hander.helloworld({}, {}, callback);
});

it('should return the hellworld message as json', (done) => {
const callback = (err, result) => {
assert.equal('Go Serverless v1.0! Your function executed successfully!', JSON.parse(result.body).message);
done();
};
hander.helloworld({}, {}, callback);
});
});
});
14 changes: 14 additions & 0 deletions aws-node-helloworld-tested/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "aws-node-helloworld-tested",
"version": "0.0.1",
"description": "A simple example showing a http helloworld including a unit test.",
"main": "handler.js",
"scripts": {
"test": "mocha handler.test.js"
},
"author": "Matthias Luebken",
"license": "MIT",
"devDependencies": {
"mocha": "^3.4.2"
}
}
23 changes: 23 additions & 0 deletions aws-node-helloworld-tested/serverless.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Welcome to serverless. Read the docs at https://serverless.com/framework/docs/
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should consider excluding test files

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. Added. Thanks.


service: helloworld

# The `provider` block defines where your service will be deployed
provider:
name: aws
runtime: nodejs6.10

# Exclude tests for deployment
package:
exclude:
- "*.test.js"

# The `functions` block defines what code to deploy
functions:
helloWorld:
handler: handler.helloworld
# The `events` block defines how to trigger the handler.helloWorld code
events:
- http:
path: hello-world
method: get
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
"markdown-magic": "^0.1.13"
},
"devDependencies": {
"eslint": "^3.19.0",
"eslint-config-airbnb": "^15.0.1",
"eslint-plugin-import": "^2.3.0",
"eslint-plugin-jsx-a11y": "^5.0.3",
"eslint-plugin-react": "^7.0.1",
"markdown-magic": "^0.1.14"
}
}