Skip to content
This repository has been archived by the owner on Jun 19, 2020. It is now read-only.

Adding Backend serverless code and functions #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@
npm-debug.log*
yarn-debug.log*
yarn-error.log*

.env
.dynamodb/
40 changes: 31 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,37 @@ The project template for Code for Baltimore github projects. This project will
We've included a `docs` folder with a template [Tech Spec](/docs/Tech_Spec.md) and [Best Practices](/docs/Best_Practices.md) document, though using Github's Wiki capabilities is also a good idea. This will get you started with documenting your project. Other documents and relevant information that has no other place can live in the `docs` folder. Replace this paragraph with a brief breakdown of what you've included in your `docs` folder.

## Setup
What does someone need to do to get started with your project? Do they need to:
* install software?
* run some commands?
* do something else?

In this section of the `README` you should include any information a new contributor or user of the project needs to know to get running locally and setup.

To start, have `node12`+ and `npm` installed. You may also need `aws-cli` installed and a `local` config added. The Key and Secret can be any words, they just have to exist.
Then run :
```bash
npm install

sls dynamodb install

# or :
sls dynamodb install --localPath ./dynamodb

```
You will need an `.env` file created with certain values filled in.
```bash
touch .env
echo 'NODE_ENV=local
STAGE=local
REGION=localhost
ENDPOINT=http://localhost:4000
DEFAULT_ACCESS_KEY=<whatever key you want>
DEFAULT_SECRET=<whatever secret you want>
' >> ./.env
```
To spin up the backend locally run
```bash
sls offline start
```

To run the front-end application run
```bash
npm start
```
## Using this product
How would someone use this product? Give a few examples here.

Expand All @@ -27,8 +51,6 @@ If referencing any third party service, code, etc, cite it here.

This template is in use on a number of other Code for Baltimore projects. For examples of use in various ways, please see the followings examples:

* *NodeJs* = [JuryInstructions](https://github.com/CodeForBaltimore/JuryInstructions)
* *Python* = [ProjectTemplate-Python](https://github.com/CodeForBaltimore/ProjectTemplate-Python)

<p align="center">
<img src="docs/img/CfB.png" width="400">
Expand Down
24 changes: 24 additions & 0 deletions lambda/handlers/dataEntry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const AWS = require('aws-sdk');
const uuid = require('uuid');

const dynamoDb = new AWS.DynamoDB({
region: process.env.REGION,
endpoint: process.env.ENDPOINT,
apiVersion: '2012-08-10',
accessKeyId: process.env.DEFAULT_ACCESS_KEY,
secretAccessKey: process.env.DEFAULT_SECRET
});
module.exports.handler = async event => {
const timestamp = new Date().getTime();
const {stuff, whatever} = event.body;
const id = uuid.v4();

const res = await dynamoDb.putItem('baltimoreResourcesTable', {

});

return {
statusCode: 200,
body: JSON.stringify(res)
}
}
13 changes: 13 additions & 0 deletions lambda/handlers/heyBuddy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports.handler = async event => {
return {
statusCode: 200,
body: JSON.stringify(event.queryStringParameters.test)
}
}

module.exports.another = async event => {
return {
statusCode: 200,
body: 'wwwwwwwwaaaaaaaaaaaaaaaa'
}
}
12 changes: 12 additions & 0 deletions lambda/lambda.serverless.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
heyBuddy:
handler: lambda/handlers/heyBuddy.handler
events:
- http: GET /heybuddy
anotherOne:
handler: lambda/handlers/heyBuddy.another
events:
- http: GET /another
dataEntry:
handler: lambda/handlers/dataEntry.handler
events:
- http: POST /dataEntry
Loading