Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/saiorama/remake-serverless

Read and write JSON files to (my) S3 using presigned urls (needs an account). To write to your own S3, fork this code, edit constants in `scratchpad.js`, and specify the right env vars in your presigned url lambda
https://github.com/saiorama/remake-serverless

aws aws-lambda aws-s3 cognito handlebars handlebarsjs remake

Last synced: 1 day ago
JSON representation

Read and write JSON files to (my) S3 using presigned urls (needs an account). To write to your own S3, fork this code, edit constants in `scratchpad.js`, and specify the right env vars in your presigned url lambda

Awesome Lists containing this project

README

        

## remake-serverless

### Getting Oriented

`remake-serverless` is built on top of the `remake` client side [framework](https://github.com/remake/remake-framework).

`remote-serverless` provides a serverless, globally available backend to store JSON files spit out by the core `remake-framework`. The original remake framework linked above uses an express server to receive and persist files.

`ScratchPad` is the name of the serverless backend which manages user auth (built on AWS Cognito), generation of presigned urls (AWS Lambda + S3), and saving json files to S3.

1. User auth is used to create and limit users to a user specific namespace in the ScratchPad backend
2. Presigned URLs are a safe way to PUT JSON files in S3
3. Your JSON files are publicly visible

### Getting Started

1. Clone this repository `git clone https://github.com/saiorama/remake-serverless.git`
2. ...then `cd remake-serverless`
3. Start `http-server` or any other such static website server
3. Visit `http://localhost:8080/remake.html`

You should see a set of To-Dos along with a message that you need to signup/login to use the ScratchPad server. Without signing up, you will only be able to save and read JSONs locally.

Clicking on the Sign up/Login link takes you to an AWS Cognito page where you can create or log in to your ScratchPad account

### Saving your latest JSON to ScratchPad

Every time you click on `Save`, it automatically writes the JSON file to S3. Keep in mind that this is just a demo repository. Your own implementation will vary, e.g., you can choose to implement periodic saves.

### Reading your JSON files from ScratchPad

Login and then refresh the page, it should read the latest JSON file from SratchPad. Keep in mind that this is just a demo repository. Your own implementation will vary, e.g., in your project, you can force the user to click on a button before loading the JSON.

## FAQs

1. What is my namespace?

All JSON files are stored inside user specific directories inside the main ScratchPad bucket. The root URL of that directory is `https://moogle.cc/gallery/nirvaancms/attachments/`. Inside the root URL, each ScratchPad user gets a direcctory whose name is determined is as follows - strip out any non-alphanumeric character from the email you used to sign up for ScratchPad. That's your working directory. E.g., if you use [email protected] to sign up for ScratchPad, your working directory is `nameexamplecom`. The URL of your working directory will be `/nameexamplecom`.

This becomes your namespace

2. Can I create subdirectories within my namespace?

Yes. While requesting a presigned URL from the ScratchPad backend, you have to send a query param called `filename`. `Filename` can be the full path to a specific json file.

E.g., if you are using this repo for a class project for a CS101 course, you may want to save files inside `classprojects/cs101/content.json`. In this case, simply pass `classprojects/cs101/content.json` as the `filename` parameter.

3. How do I name my JSON files?

By default, filenames are generated by replacing all non-alphanumeric chars in the current URL (minus http:// or https://)into hyphens.

E.g., if you are using remake on `https://example.com/classproject/cs101/index.html`, the default json filename will be `example-com-classprojects-cs101-index-html.json`

Of course, this is just a demo project so you can implement your own naming convention for JSON file names.