You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This workshop is designed to help you start building [Serverless](https://martinfowler.com/articles/serverless.html)[ReactJS](https://reactjs.org/) Apps. For simplification purposes we will be creating a basic **Contact Us** application. The application will be implemented using a [3 Tier Architecture](https://en.wikipedia.org/wiki/Multitier_architecture#Three-tier_architecture):
4
-
-**Presentation** (aka Frontend)
3
+
This workshop is designed to help you start building [Serverless](https://martinfowler.com/articles/serverless.html)[React](https://reactjs.org/) Apps using the ```AWS``` services. The main goal is for you to have the full infrastructure running on your local setup to easily develop and test.
4
+
5
+
For simplification purposes we will be creating a basic **Contact Us** application. The application will be implemented using a [3 Tier Architecture](https://en.wikipedia.org/wiki/Multitier_architecture#Three-tier_architecture):
6
+
-**Presentation** using [ReactJS](https://reactjs.org/)
7
+
This tier is also known as Front-end.
5
8
- A page with a contact form with a name, email and message.
6
9
- A page with a list of received contacts.
7
-
-**Logic** (aka Backend)
10
+
-**Logic** using [AWS Lambda](https://aws.amazon.com/lambda/)
11
+
This tier is also known as Back-end.
8
12
- Two endpoints for submitting the form and reading all contacts.
9
-
-**Data** (aka Persistency)
13
+
-**Data** using [AWS DynamoDB](https://aws.amazon.com/dynamodb/) and [AWS DynamoDB-local](https://hub.docker.com/r/amazon/dynamodb-local/)
14
+
This tier is also known as Persistency.
10
15
- A database to store all contacts.
11
16
17
+
### What will not be covered (for now)
18
+
- Authentication
19
+
- Authorization
20
+
- Deployment to AWS
21
+
22
+
## Table of Contents
23
+
24
+
-[Pre-requisites](#pre-requisites)
25
+
-[Running locally](#running-locally)
26
+
-[Essentials](#essentials)
27
+
12
28
## Pre-requisites
13
29
14
30
You should be familiar with the Composition Pattern because React recommends it. Please have a look at the [Composition vs Inheritance](https://reactjs.org/docs/composition-vs-inheritance.html) page from the React docs.
15
31
16
-
Although we will not cover deployment into AWS in this workshop, you still need to create an [AWS Free Tier](https://aws.amazon.com/free/) account in order to use the local stack. After creating your account and installing the software from the [Logic](#Logic) section, please run the following command to configure your local default settings:
32
+
Although we will not cover deployment into AWS in this workshop, **you still need to create** an [AWS Free Tier](https://aws.amazon.com/free/) account in order to use the local stack.
33
+
34
+
After creating your account and installing the software from the [Logic](#logic) section, please run the following command to configure your local default settings:
17
35
18
36
```
19
37
aws configure
@@ -30,6 +48,7 @@ Via npm (already in package.json):
30
48
-[ReactJS](https://reactjs.org/) - A JavaScript library for building user interfaces.
31
49
-[React Router](https://github.com/ReactTraining/react-router) - Declarative routing for React.
32
50
-[React Router Dom](https://github.com/ReactTraining/react-router/tree/master/packages/react-router-dom) - DOM bindings for React Router.
51
+
-[cross-env](https://github.com/kentcdodds/cross-env) - Set and use environment variables across platforms.
33
52
34
53
### Logic
35
54
@@ -54,38 +73,139 @@ For the data tier we will be using:
54
73
55
74
Via npm (already in package.json):
56
75
-[AWS SDK](https://github.com/aws/aws-sdk-js) - AWS SDK for JavaScript.
76
+
-[cross-env](https://github.com/kentcdodds/cross-env) - Set and use environment variables across platforms.
57
77
58
78
## Running Locally
59
79
60
-
To run this project locally in development mode you need to clone the repository and either use the [start.sh](start.sh) script or start the 3 tiers independently (using the following commands):
The tools used here support hot reloading, which means that everytime you change the code it will automatically be reflected on the local application.
127
+
128
+
**Note:** changes to the SAM template.yaml file will only be reflected when you restart the ```sam local start-api...``` command.
129
+
130
+
131
+
### AWS
132
+
133
+
- You need at least an [AWS Free Tier](https://aws.amazon.com/free/) account in order to use the local or cloud stack.
134
+
- To configure locally your AWS account run the command```aws configure```:
135
+
- Credentials will be stored in```~/.aws/credentials```and are a set of ```access_key_id``` + ```secret_access_key```.
136
+
- Configuration will be stored in```~/.aws/config```and requires at least the region.
137
+
138
+
### Docker
139
+
140
+
- A local docker network called ```lambda-local``` needs to be created to easily support communication between ```lambda``` and ```dynamodb```.
141
+
142
+
### JavaScript
143
+
144
+
- [Promises](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) are a mechanism used to support asynchronous operations, that gives you ```resolve``` and ```reject``` functions to handle the result after it was processed. A good example of this is the [axios](https://github.com/axios/axios) http client:
145
+
146
+
147
+
```javascript
148
+
axios.post('/user', {
149
+
firstName: 'Fred',
150
+
lastName: 'Flintstone'
151
+
})
152
+
.then(function (response) {
153
+
console.log(response);
154
+
})
155
+
.catch(function (error) {
156
+
console.log(error);
157
+
});
158
+
```
159
+
160
+
### ReactJS
161
+
162
+
[ReactJS](https://reactjs.org/)
163
+
164
+
- Composition over Inheritance, see [Composition vs Inheritance](https://reactjs.org/docs/composition-vs-inheritance.html).
165
+
- Updates and renders the right components on data change.
166
+
- JSX syntax (xml-like):
167
+
```jsx
168
+
class HelloMessage extends React.Component {
169
+
render() {
170
+
return (
171
+
<div>
172
+
Hello {this.props.name}
173
+
</div>
174
+
);
175
+
}
176
+
}
64
177
```
178
+
- ***props*** holds the Component attributes.
179
+
- ***state*** holds the Component state.
180
+
- **MUST** know methods:
181
+
- ```render()``` - defines how a Component shall be rendered.
182
+
- ```componentWillMount()``` - perform actions before component is mounted (e.g.: fetch data)
- Relies on a file called ```template.yaml``` that specifies the Resources (Functions, Database, APIs, etc). This is an extension to [CloudFormation](https://aws.amazon.com/cloudformation/).
198
+
- Has a command line tool ```sam``` that uses the ```aws-cli``` as a base.
199
+
200
+
### AWS DynamoDB
201
+
202
+
[DynamoDB](https://aws.amazon.com/dynamodb/)
203
+
204
+
- Local usage is possible with the docker image [amazon/dynamodb-local](https://hub.docker.com/r/amazon/dynamodb-local/).
205
+
- It is configured to run locally at **Port 8000**
86
206
87
-
##Changing the code
207
+
### Cross-Origin Resource Sharing (CORS)
88
208
89
-
Due to hot reloading, everytime you change the code it will automatically be reflected on the application.
0 commit comments