Skip to content

Commit bcb1bcd

Browse files
committed
fix: add dynamodb index
1 parent 1070296 commit bcb1bcd

File tree

5 files changed

+96
-68
lines changed

5 files changed

+96
-68
lines changed

.env.template

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
MYSQL_SERVER=localhost
2-
MYSQL_DATABASE=techchallenge
3-
MYSQL_PORT=3306
4-
MYSQL_USERID=techchallenge
5-
MYSQL_PASSWORD=techchallengeFIAP
61
MercadoPago_WebhookSecret=1231231231232
72
MercadoPago_AccessToken=APP_USR-
83
MercadoPago_NotificationUrl=https://a42d-mercadopago
@@ -11,6 +6,9 @@ HybridCache_LocalCacheExpiration=01:00:00
116
HybridCache_Flags=DisableDistributedCache
127
JwtOptions_Issuer=https://localhost:7000
138
JwtOptions_Audience=https://localhost:7000
14-
JwtOptions_SigningKey=
9+
JwtOptions_SigningKey=kasdfhkasjdfhkajdfhkajfhkasdjfhkasdjfhkasdf
1510
JwtOptions_ExpirationSeconds=301
1611
JwtOptions_UseAccessToken=false
12+
AwsSettings__Region=us-east-1
13+
AwsSettings__ClientSecret=1231231313123
14+
AwsSettings__ClientId=123123123

docker-compose.yml

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
services:
22
api:
3-
depends_on:
4-
- database
53
container_name: payment_api
64
build:
75
context: ./
@@ -20,7 +18,6 @@
2018
ports:
2119
- 8080:8080
2220
environment:
23-
- ConnectionStrings__MySql=Server=database;Database=${MYSQL_DATABASE};Uid=${MYSQL_USERID};Pwd=${MYSQL_PASSWORD};Port=${MYSQL_PORT}
2421
- ASPNETCORE_ENVIRONMENT=Development
2522
- Serilog__WriteTo__2__Args__serverUrl=http://seq:5341
2623
- Serilog__Enrich__0=FromLogContext
@@ -35,29 +32,6 @@
3532
- JwtOptions__Audience=${JwtOptions_Audience}
3633
- JwtOptions__ExpirationSeconds=${JwtOptions_ExpirationSeconds}
3734
- JwtOptions__UseAccessToken=${JwtOptions_UseAccessToken}
38-
database:
39-
container_name: restaurant_db
40-
build:
41-
context: ./database
42-
dockerfile: Dockerfile
43-
tags:
44-
- techchallenge/restaurant_db
45-
restart: always
46-
environment:
47-
- MYSQL_ROOT_PASSWORD=admin
48-
- MYSQL_DATABASE=${MYSQL_DATABASE}
49-
- MYSQL_USER=${MYSQL_USERID}
50-
- MYSQL_PASSWORD=${MYSQL_PASSWORD}
51-
ports:
52-
- 3306:3306
53-
networks:
54-
- tech-challenge
55-
56-
# adminer:
57-
# image: adminer
58-
# restart: always
59-
# ports:
60-
# - 27017:27017
6135

6236
seq:
6337
image: datalust/seq:latest

src/Bmb.Payment.DI/HealthChecks/DynamoDbTableHealthCheck.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ public static IHealthChecksBuilder AddDynamoDbHealthCheck(this IHealthChecksBuil
4444
HealthStatus? failureStatus = default, IEnumerable<string> tags = default,
4545
TimeSpan? timeout = default)
4646
{
47-
4847
return builder.Add(new HealthCheckRegistration(
4948
$"{tableName}-health",
5049
sp => new DynamoDbTableHealthCheck(sp.GetRequiredService<IAmazonDynamoDB>(), tableName),

terraform/main.tf

Lines changed: 86 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,60 @@ data "aws_eks_cluster" "techchallenge_cluster" {
1010
# DATABASE
1111
##############################
1212

13+
14+
resource "aws_dynamodb_table" "payment_orders_replica" {
15+
name = "Payment-OrdersReplica"
16+
billing_mode = "PAY_PER_REQUEST"
17+
hash_key = "Id"
18+
stream_enabled = false
19+
20+
attribute {
21+
name = "Id"
22+
type = "S"
23+
}
24+
25+
ttl {
26+
attribute_name = "ExpireAt"
27+
}
28+
}
29+
30+
resource "aws_dynamodb_table" "payments_table" {
31+
name = "Payments"
32+
billing_mode = "PAY_PER_REQUEST"
33+
hash_key = "Id"
34+
stream_enabled = false
35+
36+
attribute {
37+
name = "Id"
38+
type = "S"
39+
}
40+
attribute {
41+
name = "ExternalReference"
42+
type = "S"
43+
}
44+
45+
global_secondary_index {
46+
name = "ExternalReference-index"
47+
hash_key = "ExternalReference"
48+
projection_type = "ALL"
49+
write_capacity = 1
50+
read_capacity = 1
51+
}
52+
}
53+
1354
locals {
14-
jwt_issuer = var.jwt_issuer
15-
jwt_aud = var.jwt_aud
16-
docker_image = var.api_docker_image
55+
jwt_issuer = var.jwt_issuer
56+
jwt_aud = var.jwt_aud
57+
docker_image = var.api_docker_image
58+
aws_access_key = var.api_access_key_id
59+
aws_secret_access_key = var.api_secret_access_key
60+
aws_region = "us-east-1"
61+
jwt_signing_key = var.jwt_signing_key
1762
}
1863

1964

2065
##############################
21-
# CONFIGS/SECRETS
66+
# NAMESPACE
2267
##############################
2368

2469
resource "kubernetes_namespace" "payment" {
@@ -27,40 +72,44 @@ resource "kubernetes_namespace" "payment" {
2772
}
2873
}
2974

75+
##############################
76+
# CONFIGS/SECRETS
77+
##############################
78+
79+
3080
resource "kubernetes_config_map_v1" "config_map_api" {
3181
metadata {
32-
name = "configmap-api"
82+
name = "configmap-payment-api"
3383
namespace = "payment"
3484
labels = {
35-
"app" = "api"
85+
"app" = "payment-api"
3686
"terraform" = true
3787
}
3888
}
3989
data = {
4090
"ASPNETCORE_ENVIRONMENT" = "Development"
91+
"MercadoPago__NotificationUrl" = ""
4192
"Serilog__WriteTo__2__Args__serverUrl" = "http://svc-seq:80"
4293
"Serilog__WriteTo__2__Args__formatter" = "Serilog.Formatting.Json.JsonFormatter, Serilog"
43-
"MercadoPago__NotificationUrl" = ""
4494
"Serilog__Enrich__0" = "FromLogContext"
4595
"HybridCache__Expiration" = "01:00:00"
4696
"HybridCache__LocalCacheExpiration" = "01:00:00"
4797
"HybridCache__Flags" = "DisableDistributedCache"
4898
"JwtOptions__Issuer" = local.jwt_issuer
4999
"JwtOptions__Audience" = local.jwt_aud
50-
"JwtOptions__SigningKey" = var.jwt_signing_key
51100
"JwtOptions__ExpirationSeconds" = 3600
52101
"JwtOptions__UseAccessToken" = true
53-
# "SqsSettings__QueueName" = local.events_queue_name
54-
"SqsSettings__Enabled" = true
55-
"SqsSettings__Region" = "us-east-1"
56-
"SqsSettings__ClientId" = var.api_access_key_id
57-
"SqsSettings__ClientSecret" = var.api_secret_access_key
102+
"JwtOptions__SigningKey" = local.jwt_signing_key
103+
"AwsSettings__Region" = local.aws_region
104+
"AwsSettings__ClientSecret" = local.aws_secret_access_key
105+
"AwsSettings__ClientId" = local.aws_access_key
106+
58107
}
59108
}
60109

61-
resource "kubernetes_secret" "secret_mercadopago" {
110+
resource "kubernetes_secret" "secret_api" {
62111
metadata {
63-
name = "secret-mercadopago"
112+
name = "secret-payment-api"
64113
namespace = "payment"
65114
labels = {
66115
app = "api-pod"
@@ -78,10 +127,9 @@ resource "kubernetes_secret" "secret_mercadopago" {
78127
# API
79128
####################################
80129

81-
82130
resource "kubernetes_service" "payment-api-svc" {
83131
metadata {
84-
name = var.internal_elb_name
132+
name = var.internal_elb_name
85133
namespace = "payment"
86134
annotations = {
87135
"service.beta.kubernetes.io/aws-load-balancer-type" = "nlb"
@@ -97,40 +145,46 @@ resource "kubernetes_service" "payment-api-svc" {
97145
}
98146
type = "LoadBalancer"
99147
selector = {
100-
app : "api"
148+
app : "payment-api"
101149
}
102150
}
103151
}
104152

105153
resource "kubernetes_deployment" "deployment_payment_api" {
106-
depends_on = [kubernetes_secret.secret_mercadopago, kubernetes_config_map_v1.config_map_api]
154+
depends_on = [
155+
kubernetes_secret.secret_api,
156+
kubernetes_config_map_v1.config_map_api,
157+
# aws_dynamodb_table.payments_table,
158+
# aws_dynamodb_table.payment_orders_replica
159+
]
160+
107161
metadata {
108-
name = "deployment-payment-api"
162+
name = "deployment-payment-api"
109163
namespace = "payment"
110164
labels = {
111-
app = "api"
165+
app = "payment-api"
112166
"terraform" = true
113167
}
114168
}
115169
spec {
116170
replicas = 1
117171
selector {
118172
match_labels = {
119-
app = "api"
173+
app = "payment-api"
120174
}
121175
}
122176
template {
123177
metadata {
124-
name = "pod-api"
178+
name = "pod-payment-api"
125179
labels = {
126-
app = "api"
180+
app = "payment-api"
127181
"terraform" = true
128182
}
129183
}
130184
spec {
131185
automount_service_account_token = false
132186
container {
133-
name = "api-container"
187+
name = "payment-api-container"
134188
image = local.docker_image
135189
port {
136190
name = "liveness-port"
@@ -172,12 +226,12 @@ resource "kubernetes_deployment" "deployment_payment_api" {
172226
}
173227
env_from {
174228
config_map_ref {
175-
name = "configmap-api"
229+
name = "configmap-payment-api"
176230
}
177231
}
178232
env_from {
179233
secret_ref {
180-
name = "secret-mercadopago"
234+
name = "secret-payment-api"
181235
}
182236
}
183237
}
@@ -188,7 +242,7 @@ resource "kubernetes_deployment" "deployment_payment_api" {
188242

189243
resource "kubernetes_horizontal_pod_autoscaler_v2" "hpa_api" {
190244
metadata {
191-
name = "hpa-api"
245+
name = "hpa-payment-api"
192246
namespace = "payment"
193247
}
194248
spec {
@@ -203,7 +257,7 @@ resource "kubernetes_horizontal_pod_autoscaler_v2" "hpa_api" {
203257
metric {
204258
type = "ContainerResource"
205259
container_resource {
206-
container = "api-container"
260+
container = "payment-api-container"
207261
name = "cpu"
208262
target {
209263
average_utilization = 65
@@ -220,7 +274,7 @@ resource "kubernetes_horizontal_pod_autoscaler_v2" "hpa_api" {
220274

221275
resource "kubernetes_service" "svc_seq" {
222276
metadata {
223-
name = "svc-seq"
277+
name = "svc-seq"
224278
namespace = "payment"
225279
labels = {
226280
"terraform" = true
@@ -240,7 +294,7 @@ resource "kubernetes_service" "svc_seq" {
240294

241295
resource "kubernetes_deployment" "deployment_seq" {
242296
metadata {
243-
name = "deployment-seq"
297+
name = "deployment-seq"
244298
namespace = "payment"
245299
labels = {
246300
app = "seq"
@@ -295,4 +349,4 @@ resource "kubernetes_deployment" "deployment_seq" {
295349
}
296350
}
297351
}
298-
}
352+
}

terraform/variables.tf

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ variable "region" {
1717

1818
variable "eks_cluster_name" {
1919
type = string
20-
default = "quixada"
20+
default = "eks_dev_quixada"
2121
}
2222

2323
variable "mercadopago_webhook_secret" {
@@ -33,6 +33,7 @@ variable "mercadopago_accesstoken" {
3333
variable "jwt_signing_key" {
3434
type = string
3535
sensitive = true
36+
default = "PkOhRwy6UtniEMo7lLWp3bADctYgnDHCTvH+2YkDeGg="
3637
}
3738

3839
variable "jwt_issuer" {
@@ -49,22 +50,24 @@ variable "jwt_aud" {
4950

5051
variable "api_docker_image" {
5152
type = string
52-
default = "ghcr.io/soat-fiap/bmb.payment/api:1.0.0"
53+
default = "ghcr.io/soat-fiap/bmb.payment/api:1.2.1"
5354
}
5455

5556
variable "internal_elb_name" {
5657
type = string
57-
default = "payment-api-internal-elb"
58+
default = "api-internal-elb"
5859
}
5960

6061
variable "api_access_key_id" {
6162
type = string
6263
nullable = false
6364
sensitive = true
65+
default = ""
6466
}
6567

6668
variable "api_secret_access_key" {
6769
type = string
6870
nullable = false
6971
sensitive = true
72+
default = ""
7073
}

0 commit comments

Comments
 (0)