Working (?) courses get func
This commit is contained in:
@@ -3,7 +3,7 @@ const db = require('../../services/db');
|
|||||||
|
|
||||||
module.exports.default = async () => {
|
module.exports.default = async () => {
|
||||||
try {
|
try {
|
||||||
const courses = await db.get('eg_courses', {});
|
const courses = await db.scan('eg_courses');
|
||||||
|
|
||||||
return createResponse(200, {
|
return createResponse(200, {
|
||||||
courses: courses
|
courses: courses
|
||||||
|
|||||||
@@ -21,6 +21,16 @@ provider:
|
|||||||
name: aws
|
name: aws
|
||||||
runtime: nodejs8.10
|
runtime: nodejs8.10
|
||||||
region: us-east-2
|
region: us-east-2
|
||||||
|
iamRoleStatements:
|
||||||
|
- Effect: Allow
|
||||||
|
Action:
|
||||||
|
- dynamodb:Query
|
||||||
|
- dynamodb:Scan
|
||||||
|
- dynamodb:GetItem
|
||||||
|
- dynamodb:PutItem
|
||||||
|
- dynamodb:UpdateItem
|
||||||
|
- dynamodb:DeleteItem
|
||||||
|
Resource: "*"
|
||||||
|
|
||||||
# you can overwrite defaults here
|
# you can overwrite defaults here
|
||||||
# stage: dev
|
# stage: dev
|
||||||
@@ -56,7 +66,7 @@ provider:
|
|||||||
# - exclude-me-dir/**
|
# - exclude-me-dir/**
|
||||||
|
|
||||||
functions:
|
functions:
|
||||||
hello:
|
courses:
|
||||||
handler: handlers/courses/get.default
|
handler: handlers/courses/get.default
|
||||||
events:
|
events:
|
||||||
- http:
|
- http:
|
||||||
@@ -109,19 +119,23 @@ functions:
|
|||||||
# Description: "Description for the output"
|
# Description: "Description for the output"
|
||||||
# Value: "Some output value"
|
# Value: "Some output value"
|
||||||
resources:
|
resources:
|
||||||
|
Resources:
|
||||||
coursesTable:
|
coursesTable:
|
||||||
Type: AWS::DynamoDB::Table
|
Type: AWS::DynamoDB::Table
|
||||||
Properties:
|
Properties:
|
||||||
TableName: eg_courses
|
TableName: eg_courses
|
||||||
AttributeDefinitions:
|
AttributeDefinitions:
|
||||||
- AttributeName: name
|
- AttributeName: name
|
||||||
AttributeType: s
|
AttributeType: S
|
||||||
KeySchema:
|
KeySchema:
|
||||||
- AttributeName: name
|
- AttributeName: name
|
||||||
KeyType: HASH
|
KeyType: HASH
|
||||||
Tags:
|
Tags:
|
||||||
- Key: app
|
- Key: app
|
||||||
Value: ecs-grader
|
Value: ecs-grader
|
||||||
|
ProvisionedThroughput:
|
||||||
|
ReadCapacityUnits: 1
|
||||||
|
WriteCapacityUnits: 1
|
||||||
|
|
||||||
plugins:
|
plugins:
|
||||||
- serverless-offline
|
- serverless-offline
|
||||||
@@ -21,6 +21,12 @@ const get = async (tableName, keyMap) => {
|
|||||||
return res && res.Item;
|
return res && res.Item;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const scan = async (tableName) => {
|
||||||
|
const res = await dynamoClient.scan({
|
||||||
|
TableName: tableName
|
||||||
|
}).promise();
|
||||||
|
};
|
||||||
|
|
||||||
const queryByID = async (tableName, idKeyName, id) => {
|
const queryByID = async (tableName, idKeyName, id) => {
|
||||||
// querying by id can be used when we are querying a table
|
// querying by id can be used when we are querying a table
|
||||||
// that has a sortKey, but we don't need to use the sortKey
|
// that has a sortKey, but we don't need to use the sortKey
|
||||||
|
|||||||
Reference in New Issue
Block a user