Skip to content

Commit 678fa1c

Browse files
author
Hans Klunder
committed
Added GCP version to the README
1 parent b33d52a commit 678fa1c

File tree

1 file changed

+75
-42
lines changed

1 file changed

+75
-42
lines changed

README.md

Lines changed: 75 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,43 @@
1-
Docker Voting App done Serverless Style
2-
=======================================
1+
# Docker Voting App done Serverless Style
32

43
## Introduction
5-
I was reading [Deploy the Voting App to AWS ECS with Fargate] by Tony Pujals where he describes how to run the [Docker Voting app demo] on AWS using [AWS Fargate]
64

7-
[Deploy the Voting App to AWS ECS with Fargate]:https://medium.com/@tonypujals/deploy-the-voting-app-to-aws-ecs-with-fargate-
8-
[Docker Voting app demo]:https://github.com/subfuzion/docker-voting-app-nodejs
9-
[AWS Fargate]:https://aws.amazon.com/fargate/
5+
I was reading [Deploy the Voting App to AWS ECS with Fargate] by Tony Pujals
6+
where he describes how to run the [Docker Voting app demo] on AWS using [AWS
7+
Fargate]
108

11-
Of course I understand that the Docker Voting app is a showcase of Docker technology and that it's not the most exciting application from a business perspective. I also understand that people want to show how you can take Docker technology to AWS. However in my mind I started wondering: if I would take this to AWS would I be following the same path ? Or would I go Serverless ?
9+
[deploy the voting app to aws ecs with fargate]: https://medium.com/@tonypujals/deploy-the-voting-app-to-aws-ecs-with-fargate-
10+
[docker voting app demo]: https://github.com/subfuzion/docker-voting-app-nodejs
11+
[aws fargate]: https://aws.amazon.com/fargate/
12+
13+
Of course I understand that the Docker Voting app is a showcase of Docker
14+
technology and that it's not the most exciting application from a business
15+
perspective. I also understand that people want to show how you can take Docker
16+
technology to AWS. However in my mind I started wondering: if I would take this
17+
to AWS would I be following the same path ? Or would I go Serverless ?
1218

1319
Given the title: I went Serverless!
1420

15-
The voting application is recreated using AWS ApiGateway and AWS DynamoDB only. The queue service could be implemented using SNS, however one typically uses a queue to ensure scalability of the database or to allow for maintenance. Both are handled by AWS DynamoDB automatically.
21+
The voting application is recreated using AWS ApiGateway and AWS DynamoDB only.
22+
The queue service could be implemented using SNS, however one typically uses a
23+
queue to ensure scalability of the database or to allow for maintenance. Both
24+
are handled by AWS DynamoDB automatically.
1625

1726
## Creating the schema
27+
1828
Looking at the sources of the voting app there are two endpoints:
19-
- POST /vote where you can post a vote by posting JSON like `{"vote":"a"}` or `{"vote":"b"}`
20-
- GET /results which will give you results like:
29+
30+
* POST /vote where you can post a vote by posting JSON like `{"vote":"a"}` or
31+
`{"vote":"b"}`
32+
* GET /results which will give you results like:
33+
2134
```json
2235
{
23-
"success" : true,
24-
"result" : {
25-
"a" : 0,
26-
"b" : 0
27-
}
36+
"success": true,
37+
"result": {
38+
"a": 0,
39+
"b": 0
40+
}
2841
}
2942
```
3043

@@ -45,6 +58,7 @@ Creating a JSON schema produces the following for /vote
4558
}
4659
}
4760
```
61+
4862
and for /results
4963

5064
```json
@@ -70,45 +84,59 @@ and for /results
7084
}
7185
```
7286

73-
Loading these in APIgateway ensures for /vote that only valid POST requests are accepted.
87+
Loading these in APIgateway ensures for /vote that only valid POST requests are
88+
accepted.
7489

7590
## DynamoDB
76-
The DynamoDB instance with partion key `topic` only holds one record with `topic` value `default` and a numeric value for `a` and `b`
91+
92+
The DynamoDB instance with partion key `topic` only holds one record with
93+
`topic` value `default` and a numeric value for `a` and `b`
7794

7895
## APIgateway integration
79-
A succesful POST operation must result in a increment of the counter for the subject of the vote in the database.
80-
This is achieved by adding the following integration request mapping template to the POST operation:
96+
97+
A succesful POST operation must result in a increment of the counter for the
98+
subject of the vote in the database. This is achieved by adding the following
99+
integration request mapping template to the POST operation:
100+
81101
```json
82102
{
83-
"TableName" : "VoteAppDynamoDBTable",
84-
"Key": {
85-
"topic": {
86-
"S":"default"
87-
}
88-
},
89-
"UpdateExpression": "ADD $input.path('$.vote') :inc",
90-
"ExpressionAttributeValues": {
91-
":inc": {
92-
"N": "1"
93-
}
103+
"TableName": "VoteAppDynamoDBTable",
104+
"Key": {
105+
"topic": {
106+
"S": "default"
94107
}
108+
},
109+
"UpdateExpression": "ADD $input.path('$.vote') :inc",
110+
"ExpressionAttributeValues": {
111+
":inc": {
112+
"N": "1"
113+
}
114+
}
95115
}
96116
```
97-
This, together with the rest of the integration configuration, will transform the POST operation into a call to DynamoDB to increment the number of votes for the subject provided.
98117

99-
Then when pulling results the GET operation needs to be transformed into a query on DynamoDB using an integration request mapping template
118+
This, together with the rest of the integration configuration, will transform
119+
the POST operation into a call to DynamoDB to increment the number of votes for
120+
the subject provided.
121+
122+
Then when pulling results the GET operation needs to be transformed into a query
123+
on DynamoDB using an integration request mapping template
124+
100125
```json
101126
{
102-
"TableName" : "VoteAppDynamoDBTable",
103-
"KeyConditionExpression": "topic = :v1",
104-
"ExpressionAttributeValues": {
105-
":v1": {
106-
"S": "default"
107-
}
127+
"TableName": "VoteAppDynamoDBTable",
128+
"KeyConditionExpression": "topic = :v1",
129+
"ExpressionAttributeValues": {
130+
":v1": {
131+
"S": "default"
108132
}
133+
}
109134
}
110135
```
111-
and the response needs to be mapped to the schema listed above using an integration response mapping template
136+
137+
and the response needs to be mapped to the schema listed above using an
138+
integration response mapping template
139+
112140
```
113141
#set($inputRoot = $input.path('$'))
114142
{
@@ -124,8 +152,13 @@ and the response needs to be mapped to the schema listed above using an integrat
124152
}
125153
}
126154
```
127-
As long as no votes have been casted it could be that the whole record does not exist yet or that `a` or `b` is still non-existent. This template takes care of these edge cases.
128155

129-
The full AWS Cloudformation template can be found [here].
156+
As long as no votes have been casted it could be that the whole record does not
157+
exist yet or that `a` or `b` is still non-existent. This template takes care of
158+
these edge cases.
159+
160+
The full AWS Cloudformation template can be found [here]. There is also a
161+
[version using Google Firebase].
130162

131-
[here]:voteApp-CF-template.json
163+
[here]: voteApp-CF-template.
164+
[version using google firebase]: https://github.com/seriousme/docker-voting-app-gcp

0 commit comments

Comments
 (0)