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
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]
6
4
7
-
[Deploy the Voting App to AWS ECS with Fargate]:https://medium.com/@tonypujals/deploy-the-voting-app-to-aws-ecs-with-fargate-
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]
10
8
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-
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 ?
12
18
13
19
Given the title: I went Serverless!
14
20
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.
16
25
17
26
## Creating the schema
27
+
18
28
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
+
21
34
```json
22
35
{
23
-
"success": true,
24
-
"result": {
25
-
"a": 0,
26
-
"b": 0
27
-
}
36
+
"success": true,
37
+
"result": {
38
+
"a": 0,
39
+
"b": 0
40
+
}
28
41
}
29
42
```
30
43
@@ -45,6 +58,7 @@ Creating a JSON schema produces the following for /vote
45
58
}
46
59
}
47
60
```
61
+
48
62
and for /results
49
63
50
64
```json
@@ -70,45 +84,59 @@ and for /results
70
84
}
71
85
```
72
86
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.
74
89
75
90
## 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`
77
94
78
95
## 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:
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.
98
117
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
+
100
125
```json
101
126
{
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"
108
132
}
133
+
}
109
134
}
110
135
```
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
+
112
140
```
113
141
#set($inputRoot = $input.path('$'))
114
142
{
@@ -124,8 +152,13 @@ and the response needs to be mapped to the schema listed above using an integrat
124
152
}
125
153
}
126
154
```
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.
128
155
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].
130
162
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