Hallo!
This project creates a REST API with NodeJS, Express and it's configured to use AWS S3 + DynamoDB.
(An instance of this server is currently being hosted in a AWS-EC2 machine. Its endpoints are being used on the front-end project. Previously all requests were being made directly on the front-end and data was being hosted on Firebase Cloud Firestore and Firebase Cloud Storage)
Cheers!
First install project packages. On your terminal, run:
yarn
If you don't have yarn installed, see how you can do it.
Before starting the server, you'll have to create a .env
file in your project root folder and fill in the variables below:
AWS_ACCESS_KEY_ID=''
AWS_SECRET_ACCESS_KEY=''
AWS_DEFAULT_REGION=''
AWS_BUCKET_NAME=''
AWS_TABLE_NAME=''
In order to do that you must go through the following steps:
- Create an account on AWS.
- Look for IAM (Identity and Access Management) under AWS services and add a new user.
- When choosing an user name, mark the checkbox Programmatic access under the section Select AWS access type and click next.
- When you reach step 2, select the box Attach existing policies directly, then search and select checkboxes for AmazonS3FullAccess and AmazonDynamoDBFullAccess.
- When you finish you'll receive an Access key ID and Secret access key. Fill in both variables
AWS_ACCESS_KEY_ID
andAWS_SECRET_ACCESS_KEY
and store them safely.
- For
AWS_DEFAULT_REGION
, check the region column on this table. Keep in mind that when doing steps 4 and 5 your regions should be the same. - Look for S3 under AWS services and create a new bucket.
- Define a bucket name (you'll use it to fill in
AWS_BUCKET_NAME
variable) - When you reach step 3, it's important to uncheck all checkboxes for public access and public bucket policies, so that image URL's can be reacheable publicly.
- Define a bucket name (you'll use it to fill in
- Look for DynamoDB under AWS services and create a new table.
- Define a table name (later you'll use it to fill in
AWS_TABLE_NAME
variable) and primary key as 'imageId'. Finish the steps to create the table.
- Define a table name (later you'll use it to fill in
If you followed everything correctly you'll be able to run the server locally and make requests to it.
In the project directory, you can run:
Runs the server in the development mode.
Open http://localhost:5000/api/image to view a GET
response in the browser.
The server will reload if you make edits. (nodemon
will take care of that for you).
Launches the test runner in the interactive watch mode.
See the section about running tests for more information.