Working (?) courses get func
This commit is contained in:
@@ -3,7 +3,7 @@ const db = require('../../services/db');
|
||||
|
||||
module.exports.default = async () => {
|
||||
try {
|
||||
const courses = await db.get('eg_courses', {});
|
||||
const courses = await db.scan('eg_courses');
|
||||
|
||||
return createResponse(200, {
|
||||
courses: courses
|
||||
|
||||
@@ -21,6 +21,16 @@ provider:
|
||||
name: aws
|
||||
runtime: nodejs8.10
|
||||
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
|
||||
# stage: dev
|
||||
@@ -56,7 +66,7 @@ provider:
|
||||
# - exclude-me-dir/**
|
||||
|
||||
functions:
|
||||
hello:
|
||||
courses:
|
||||
handler: handlers/courses/get.default
|
||||
events:
|
||||
- http:
|
||||
@@ -109,19 +119,23 @@ functions:
|
||||
# Description: "Description for the output"
|
||||
# Value: "Some output value"
|
||||
resources:
|
||||
coursesTable:
|
||||
Type: AWS::DynamoDB::Table
|
||||
Properties:
|
||||
TableName: eg_courses
|
||||
AttributeDefinitions:
|
||||
- AttributeName: name
|
||||
AttributeType: s
|
||||
KeySchema:
|
||||
- AttributeName: name
|
||||
KeyType: HASH
|
||||
Tags:
|
||||
- Key: app
|
||||
Value: ecs-grader
|
||||
Resources:
|
||||
coursesTable:
|
||||
Type: AWS::DynamoDB::Table
|
||||
Properties:
|
||||
TableName: eg_courses
|
||||
AttributeDefinitions:
|
||||
- AttributeName: name
|
||||
AttributeType: S
|
||||
KeySchema:
|
||||
- AttributeName: name
|
||||
KeyType: HASH
|
||||
Tags:
|
||||
- Key: app
|
||||
Value: ecs-grader
|
||||
ProvisionedThroughput:
|
||||
ReadCapacityUnits: 1
|
||||
WriteCapacityUnits: 1
|
||||
|
||||
plugins:
|
||||
- serverless-offline
|
||||
@@ -21,6 +21,12 @@ const get = async (tableName, keyMap) => {
|
||||
return res && res.Item;
|
||||
};
|
||||
|
||||
const scan = async (tableName) => {
|
||||
const res = await dynamoClient.scan({
|
||||
TableName: tableName
|
||||
}).promise();
|
||||
};
|
||||
|
||||
const queryByID = async (tableName, idKeyName, id) => {
|
||||
// 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
|
||||
|
||||
Reference in New Issue
Block a user