This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM node:4.2.3 | |
# Install Apex | |
WORKDIR /tmp | |
RUN wget https://raw.githubusercontent.com/apex/apex/master/install.sh && bash /tmp/install.sh | |
# Install dependencies | |
COPY package.json /srv/package.json | |
WORKDIR /srv | |
RUN npm i && mkdir /srv/src && mkdir /srv/infra |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
entry: './src/index.js', | |
target: 'node', | |
output: { | |
path: './lib', | |
filename: 'index.js', | |
libraryTarget: 'commonjs2' | |
}, | |
externals: { | |
'aws-sdk': 'aws-sdk' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "SampleProject", | |
"description": "A demo project of serverless ci", | |
"role": "arn:aws:iam::<aws account number>:role/<lambda role name>", | |
"runtime":"nodejs4.3", | |
"memory": 128, | |
"timeout": 10, | |
"handler": "lib.default", | |
"hooks": { | |
"build": "../../../node_modules/.bin/webpack --config ../../../infra/webpack.config.js", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const request = require('axios'); | |
function *search(query) { | |
let options = { | |
params: { | |
q: query, | |
sort: 'stars', | |
order: 'desc' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const Repository = require('../../../model/Repository') | |
, LambdaRunner = require('../../../lib/lambda-co-runner'); | |
function *main(e) { | |
let query = e.queryParams.q | |
, res = yield Repository.search(query); | |
return {items: res.items}; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
├── Dockerfile | |
├── infra | |
│ └── webpack.config.js | |
├── package.json | |
└── src | |
├── functions | |
│ └── getRepositories | |
│ ├── function.json | |
│ ├── src | |
│ │ └── index.js |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const co = require('co'); | |
module.exports = function(lambda) { | |
return function(e, ctx, cb) { | |
co( | |
function* () { | |
let result = yield lambda(e, ctx); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const LambdaRunner = require('co-lambda-runner') | |
, DB = require('./db'); | |
function *main(e) { | |
let id = e.params.id; | |
return yield DB.get(id); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
module.exports = function doSomething(e, ctx, cb) { | |
if (e.someParam > 0) { | |
ctx.succeed('Yay'); | |
// we add the callback here to make it testable | |
// we'll show in the next step how we make this DRY | |
if (cb) cb(); | |
} else { | |
ctx.fail('Nay') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const expect = require('chai').expect | |
, SomeLambda = require('./some-lambda-func') | |
, MockContext = require('./mock-lambda-context'); | |
describe('Some Lambda Func', function() { | |
let ctx; | |
before(function() { |