├── actions ├── .keep ├── show_readme │ ├── README.md │ ├── package.json │ └── index.js ├── show_application_css │ ├── application.css │ ├── index.js │ └── package.json ├── echo_event │ ├── index.js │ └── package.json ├── show_root │ ├── views │ │ └── index.jade │ ├── index.js │ └── package.json ├── dynamo_db │ ├── package.json │ └── index.js ├── create_user │ ├── package.json │ └── index.js └── create_session │ ├── package.json │ ├── views │ └── index.jade │ └── index.js ├── .gitignore ├── package.json ├── README.md └── db └── schema.js /actions/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /actions/show_readme/README.md: -------------------------------------------------------------------------------- 1 | ../../README.md -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /actions/*/lambda.zip 2 | /actions/*/node_modules 3 | /node_modules 4 | -------------------------------------------------------------------------------- /actions/show_application_css/application.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0 auto; 3 | width: 860px; 4 | } 5 | -------------------------------------------------------------------------------- /actions/echo_event/index.js: -------------------------------------------------------------------------------- 1 | exports.handler = function (event, context) { 2 | context.succeed(event); 3 | }; 4 | -------------------------------------------------------------------------------- /actions/show_root/views/index.jade: -------------------------------------------------------------------------------- 1 | doctype html 2 | html 3 | head 4 | title Fluct example 5 | link(href="./application-css" rel="stylesheet" type="text/css") 6 | body 7 | h1 Fluct example 8 | p This HTML was rendered by jade. 9 | -------------------------------------------------------------------------------- /actions/show_root/index.js: -------------------------------------------------------------------------------- 1 | var jade = require('jade'); 2 | 3 | exports.handler = function (event, context) { 4 | var filePath = __dirname + '/views/index.jade'; 5 | var responseBody = jade.renderFile(filePath); 6 | context.succeed(responseBody); 7 | }; 8 | -------------------------------------------------------------------------------- /actions/show_root/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "show_root", 3 | "private": true, 4 | "fluct": { 5 | "arn": "arn:aws:lambda:us-east-1:549958975024:function:show_root", 6 | "contentType": "text/html", 7 | "httpMethod": "GET", 8 | "path": "/" 9 | } 10 | } -------------------------------------------------------------------------------- /actions/dynamo_db/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "dynamo_db", 3 | "private": true, 4 | "fluct": { 5 | "arn": "arn:aws:lambda:us-east-1:549958975024:function:dynamo_db", 6 | "contentType": "text/html", 7 | "httpMethod": "GET", 8 | "path": "/dynamo_db" 9 | } 10 | } -------------------------------------------------------------------------------- /actions/show_application_css/index.js: -------------------------------------------------------------------------------- 1 | var fs = require('fs'); 2 | 3 | exports.handler = function (event, context) { 4 | var cssPath = __dirname + '/application.css'; 5 | var responseBody = fs.readFileSync(cssPath, { encoding: 'utf8' }); 6 | context.succeed(responseBody); 7 | }; 8 | -------------------------------------------------------------------------------- /actions/create_user/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "create_user", 3 | "private": true, 4 | "fluct": { 5 | "arn": "arn:aws:lambda:us-east-1:549958975024:function:create_user", 6 | "contentType": "text/html", 7 | "httpMethod": "POST", 8 | "path": "/users" 9 | } 10 | } -------------------------------------------------------------------------------- /actions/echo_event/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "echo_event", 3 | "private": true, 4 | "fluct": { 5 | "arn": "arn:aws:lambda:us-east-1:549958975024:function:echo_event", 6 | "contentType": "application/json", 7 | "httpMethod": "GET", 8 | "path": "/echo" 9 | } 10 | } -------------------------------------------------------------------------------- /actions/show_readme/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "show_readme", 3 | "private": true, 4 | "fluct": { 5 | "arn": "arn:aws:lambda:us-east-1:549958975024:function:show_readme", 6 | "contentType": "text/html", 7 | "httpMethod": "GET", 8 | "path": "/readme" 9 | } 10 | } -------------------------------------------------------------------------------- /actions/create_session/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "create_session", 3 | "private": true, 4 | "fluct": { 5 | "arn": "arn:aws:lambda:us-east-1:549958975024:function:create_session", 6 | "contentType": "text/html", 7 | "httpMethod": "GET", 8 | "path": "/sessions" 9 | } 10 | } -------------------------------------------------------------------------------- /actions/show_application_css/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "show_application_css", 3 | "private": true, 4 | "fluct": { 5 | "arn": "arn:aws:lambda:us-east-1:549958975024:function:show_application_css", 6 | "contentType": "text/css", 7 | "httpMethod": "GET", 8 | "path": "/application-css" 9 | } 10 | } -------------------------------------------------------------------------------- /actions/create_session/views/index.jade: -------------------------------------------------------------------------------- 1 | doctype html 2 | html 3 | head 4 | body(data-cookies=cookies data-url=redirectUrl) 5 | script. 6 | Object.keys(document.body.dataset.cookies).forEach(function (key) { 7 | document.cookie = key + '=' + document.body.dataset[key]; 8 | }); 9 | location.href = document.body.dataset.url; 10 | -------------------------------------------------------------------------------- /actions/show_readme/index.js: -------------------------------------------------------------------------------- 1 | var marked = require('marked'); 2 | var fs = require('fs'); 3 | 4 | exports.handler = function (event, context) { 5 | var markdownFilePath = __dirname + '/README.md'; 6 | var markdownString = fs.readFileSync(markdownFilePath, { encoding: 'utf8' }); 7 | var responseBody = marked(markdownString); 8 | context.succeed(responseBody); 9 | }; 10 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "fluct-example", 3 | "private": true, 4 | "scripts": { 5 | "migrate": "node db/schema.js" 6 | }, 7 | "fluct": { 8 | "accountId": "549958975024", 9 | "restapiId": "fxytk1yp3l", 10 | "roleName": "fluct-example-rule" 11 | }, 12 | "dependencies": { 13 | "aws-sdk": "^2.1.45", 14 | "jade": "^1.11.0", 15 | "marked": "^0.3.5" 16 | }, 17 | "devDependencies": {} 18 | } 19 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # fluct-example 2 | An example application using [fluct](https://github.com/r7kamura/fluct). 3 | 4 | - [GET /](https://fxytk1yp3l.execute-api.us-east-1.amazonaws.com/production/) 5 | - [GET /application-css](https://fxytk1yp3l.execute-api.us-east-1.amazonaws.com/production/application-css) 6 | - [GET /echo](https://fxytk1yp3l.execute-api.us-east-1.amazonaws.com/production/echo) 7 | - [GET /readme](https://fxytk1yp3l.execute-api.us-east-1.amazonaws.com/production/readme) 8 | -------------------------------------------------------------------------------- /db/schema.js: -------------------------------------------------------------------------------- 1 | var AWS = require('aws-sdk'); 2 | var dynamoDb = new AWS.DynamoDB({ region: 'us-east-1' }); 3 | 4 | dynamoDb.createTable( 5 | { 6 | TableName: 'fluct_example_users', 7 | KeySchema: [ 8 | { AttributeName: 'id', KeyType: 'HASH' } 9 | ], 10 | AttributeDefinitions: [ 11 | { AttributeName: 'id', AttributeType: 'S' } 12 | ], 13 | ProvisionedThroughput: { 14 | ReadCapacityUnits: 1, 15 | WriteCapacityUnits: 1, 16 | } 17 | }, 18 | function(error, data) { 19 | console.log([error, data]); 20 | } 21 | ); 22 | -------------------------------------------------------------------------------- /actions/dynamo_db/index.js: -------------------------------------------------------------------------------- 1 | var AWS = require('aws-sdk'); 2 | var dynamoDB = new AWS.DynamoDB({ region: 'us-east-1' }); 3 | 4 | exports.handler = function (event, context) { 5 | dynamoDB.putItem( 6 | { 7 | TableName: 'lambda_test', 8 | Item: { 9 | id: { 10 | S: crypto.randomBytes(10).toString('hex') 11 | }, 12 | user_id: { 13 | N: '1' 14 | }, 15 | } 16 | }, 17 | function (error, data) { 18 | if (error) { 19 | console.log(error); 20 | context.succeed('error'); 21 | } else { 22 | console.log(data); 23 | context.succeed('done'); 24 | } 25 | } 26 | ); 27 | }; 28 | -------------------------------------------------------------------------------- /actions/create_user/index.js: -------------------------------------------------------------------------------- 1 | var AWS = require('aws-sdk'); 2 | var crypto = require('crypto'); 3 | var dynamoDB = new AWS.DynamoDB({ region: 'us-east-1' }); 4 | 5 | exports.handler = function (event, context) { 6 | dynamoDB.putItem( 7 | { 8 | TableName: 'fluct_example_users', 9 | Item: { 10 | id: { 11 | S: crypto.randomBytes(10).toString('hex') 12 | }, 13 | name: { 14 | S: event.requestParameters.name 15 | }, 16 | } 17 | }, 18 | function (error, data) { 19 | if (error) { 20 | context.fail(error); 21 | } else { 22 | context.succeed('Created a new user'); 23 | } 24 | } 25 | ); 26 | }; 27 | -------------------------------------------------------------------------------- /actions/create_session/index.js: -------------------------------------------------------------------------------- 1 | var AWS = require('aws-sdk'); 2 | var dynamoDB = new AWS.DynamoDB({ region: 'us-east-1' }); 3 | var jade = require('jade'); 4 | 5 | exports.handler = function (event, context) { 6 | dynamoDB.getItem( 7 | { 8 | TableName: 'fluct_example_users', 9 | Key: { 10 | 'id': { 11 | 'S': '8103d5b5d22ec3046425' 12 | } 13 | } 14 | }, 15 | function (error, data) { 16 | if (error) { 17 | context.fail(error); 18 | } else { 19 | var filePath = __dirname + '/views/index.jade'; 20 | var cookies = { id: data.Item.name.S }; 21 | var responseBody = jade.renderFile( 22 | filePath, 23 | { 24 | cookies: cookies, 25 | redirectUrl: '/production' 26 | } 27 | ); 28 | context.succeed(responseBody); 29 | } 30 | } 31 | ); 32 | }; 33 | --------------------------------------------------------------------------------