├── .gitignore ├── lesson-1 └── README.md ├── lesson-2 └── README.md ├── lesson-3 ├── handler.js └── serverless.yml ├── lesson-4 ├── handler.js └── serverless.yml ├── lesson-5 ├── handler.js └── serverless.yml ├── lesson-6 ├── create.js ├── package-lock.json ├── package.json └── serverless.yml └── lesson-7 ├── create.js ├── get.js ├── package-lock.json ├── package.json └── serverless.yml /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .serverless -------------------------------------------------------------------------------- /lesson-1/README.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | aws configure 3 | ``` -------------------------------------------------------------------------------- /lesson-2/README.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | npm install -g serverless 3 | 4 | serverless 5 | 6 | sls 7 | 8 | sls create -h 9 | ``` -------------------------------------------------------------------------------- /lesson-3/handler.js: -------------------------------------------------------------------------------- 1 | module.exports.run = (event, context, callback) => { 2 | callback(null, "Hello World"); 3 | }; 4 | 5 | // module.exports.run = (event, context, callback) => { 6 | // console.log("I'm a debug statement.") 7 | // callback(null, "Hello World"); 8 | // }; 9 | 10 | // module.exports.run = (event) => { 11 | // return Promise.resolve("Hello"); 12 | // }; 13 | 14 | // module.exports.run = async event => { 15 | // return "Hello"; 16 | // }; 17 | -------------------------------------------------------------------------------- /lesson-3/serverless.yml: -------------------------------------------------------------------------------- 1 | service: my-app 2 | 3 | provider: 4 | name: aws 5 | runtime: nodejs8.10 6 | 7 | functions: 8 | helloWorld: 9 | handler: handler.run 10 | -------------------------------------------------------------------------------- /lesson-4/handler.js: -------------------------------------------------------------------------------- 1 | module.exports.run = async event => { 2 | return { 3 | statusCode: 200, 4 | body: JSON.stringify({ 5 | message: `Hello World!` 6 | }) 7 | }; 8 | }; 9 | -------------------------------------------------------------------------------- /lesson-4/serverless.yml: -------------------------------------------------------------------------------- 1 | service: my-app 2 | 3 | provider: 4 | name: aws 5 | runtime: nodejs8.10 6 | 7 | functions: 8 | helloWorld: 9 | handler: handler.run 10 | events: 11 | - http: 12 | path: / 13 | method: get 14 | -------------------------------------------------------------------------------- /lesson-5/handler.js: -------------------------------------------------------------------------------- 1 | module.exports.run = (event) => { 2 | const response = { 3 | statusCode: 200, 4 | body: JSON.stringify({ 5 | message: `Hello World!`, 6 | }), 7 | }; 8 | return Promise.resolve(response) 9 | }; 10 | -------------------------------------------------------------------------------- /lesson-5/serverless.yml: -------------------------------------------------------------------------------- 1 | service: my-app 2 | 3 | provider: 4 | name: aws 5 | runtime: nodejs8.10 6 | 7 | functions: 8 | helloWorld: 9 | handler: handler.run 10 | events: 11 | - http: 12 | path: / 13 | method: get 14 | 15 | resources: 16 | Resources: 17 | TodosDynamoDbTable: 18 | Type: 'AWS::DynamoDB::Table' 19 | Properties: 20 | TableName: todos 21 | AttributeDefinitions: 22 | - 23 | AttributeName: id 24 | AttributeType: S 25 | KeySchema: 26 | - 27 | AttributeName: id 28 | KeyType: HASH 29 | ProvisionedThroughput: 30 | ReadCapacityUnits: 1 31 | WriteCapacityUnits: 1 32 | -------------------------------------------------------------------------------- /lesson-6/create.js: -------------------------------------------------------------------------------- 1 | const uuid = require("uuid/v4"); 2 | const AWS = require("aws-sdk"); 3 | 4 | const client = new AWS.DynamoDB.DocumentClient(); 5 | 6 | module.exports.run = async event => { 7 | const data = JSON.parse(event.body); 8 | const params = { 9 | TableName: "todos", 10 | Item: { 11 | id: uuid(), 12 | text: data.text, 13 | checked: false 14 | } 15 | }; 16 | 17 | await client.put(params).promise(); 18 | 19 | return { 20 | statusCode: 200, 21 | body: JSON.stringify(params.Item) 22 | }; 23 | }; 24 | -------------------------------------------------------------------------------- /lesson-6/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "my-app", 3 | "requires": true, 4 | "lockfileVersion": 1, 5 | "dependencies": { 6 | "uuid": { 7 | "version": "3.2.1", 8 | "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.2.1.tgz", 9 | "integrity": "sha512-jZnMwlb9Iku/O3smGWvZhauCf6cvvpKi4BKRiliS3cxnI+Gz9j5MEpTz2UFuXiKPJocb7gnsLHwiS05ige5BEA==" 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /lesson-6/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "my-app", 3 | "private": true, 4 | "dependencies": { 5 | "uuid": "^3.2.1" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /lesson-6/serverless.yml: -------------------------------------------------------------------------------- 1 | service: my-app 2 | 3 | provider: 4 | name: aws 5 | runtime: nodejs8.10 6 | iamRoleStatements: 7 | - Effect: Allow 8 | Action: 9 | - dynamodb:PutItem 10 | # Resource: "arn:aws:dynamodb:*:*:table/todos" 11 | Resource: "arn:aws:dynamodb:us-east-1:853182604221:table/todos" 12 | 13 | functions: 14 | createTodo: 15 | handler: create.run 16 | events: 17 | - http: 18 | path: todos 19 | method: post 20 | 21 | resources: 22 | Resources: 23 | TodosDynamoDbTable: 24 | Type: 'AWS::DynamoDB::Table' 25 | Properties: 26 | AttributeDefinitions: 27 | - 28 | AttributeName: id 29 | AttributeType: S 30 | KeySchema: 31 | - 32 | AttributeName: id 33 | KeyType: HASH 34 | ProvisionedThroughput: 35 | ReadCapacityUnits: 1 36 | WriteCapacityUnits: 1 37 | TableName: todos 38 | -------------------------------------------------------------------------------- /lesson-7/create.js: -------------------------------------------------------------------------------- 1 | const uuid = require("uuid/v4"); 2 | const AWS = require("aws-sdk"); 3 | 4 | const client = new AWS.DynamoDB.DocumentClient(); 5 | 6 | module.exports.run = async event => { 7 | const data = JSON.parse(event.body); 8 | const params = { 9 | TableName: "todos", 10 | Item: { 11 | id: uuid(), 12 | text: data.text, 13 | checked: false 14 | } 15 | }; 16 | 17 | await client.put(params).promise(); 18 | 19 | return { 20 | statusCode: 200, 21 | body: JSON.stringify(params.Item) 22 | }; 23 | }; 24 | -------------------------------------------------------------------------------- /lesson-7/get.js: -------------------------------------------------------------------------------- 1 | const AWS = require("aws-sdk"); 2 | 3 | const dynamoDb = new AWS.DynamoDB.DocumentClient(); 4 | 5 | module.exports.run = async (event, context, callback) => { 6 | const params = { 7 | TableName: "todos", 8 | Key: { 9 | id: event.pathParameters.id 10 | } 11 | }; 12 | 13 | const result = await dynamoDb.get(params).promise(); 14 | if (result.Item) { 15 | return { 16 | statusCode: 200, 17 | body: JSON.stringify(result.Item) 18 | }; 19 | } else { 20 | return { 21 | statusCode: 404, 22 | body: JSON.stringify({ message: "Couldn't find the todo item." }) 23 | }; 24 | } 25 | }; 26 | -------------------------------------------------------------------------------- /lesson-7/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "my-app", 3 | "requires": true, 4 | "lockfileVersion": 1, 5 | "dependencies": { 6 | "uuid": { 7 | "version": "3.2.1", 8 | "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.2.1.tgz", 9 | "integrity": "sha512-jZnMwlb9Iku/O3smGWvZhauCf6cvvpKi4BKRiliS3cxnI+Gz9j5MEpTz2UFuXiKPJocb7gnsLHwiS05ige5BEA==" 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /lesson-7/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "my-app", 3 | "private": true, 4 | "dependencies": { 5 | "uuid": "^3.2.1" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /lesson-7/serverless.yml: -------------------------------------------------------------------------------- 1 | service: my-app 2 | 3 | provider: 4 | name: aws 5 | runtime: nodejs8.10 6 | iamRoleStatements: 7 | - Effect: Allow 8 | Action: 9 | - dynamodb:PutItem 10 | - dynamodb:GetItem 11 | Resource: "arn:aws:dynamodb:us-east-1:TODO-account-id:table/todos" 12 | 13 | functions: 14 | createTodo: 15 | handler: create.run 16 | events: 17 | - http: 18 | path: todos 19 | method: post 20 | getTodo: 21 | handler: get.run 22 | events: 23 | - http: 24 | path: todos/{id} 25 | method: get 26 | 27 | resources: 28 | Resources: 29 | TodosDynamoDbTable: 30 | Type: 'AWS::DynamoDB::Table' 31 | Properties: 32 | AttributeDefinitions: 33 | - 34 | AttributeName: id 35 | AttributeType: S 36 | KeySchema: 37 | - 38 | AttributeName: id 39 | KeyType: HASH 40 | ProvisionedThroughput: 41 | ReadCapacityUnits: 1 42 | WriteCapacityUnits: 1 43 | TableName: ${self:provider.environment.DYNAMODB_TABLE} 44 | --------------------------------------------------------------------------------