Skip to content

Commit 504977d

Browse files
committed
Fix deployment
1 parent 228fd73 commit 504977d

File tree

9 files changed

+51
-33
lines changed

9 files changed

+51
-33
lines changed

src/api/routes/tickets.ts

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { FastifyPluginAsync } from "fastify";
22
import * as z from "zod/v4";
33
import {
44
ConditionalCheckFailedException,
5+
DynamoDBClient,
56
QueryCommand,
67
ScanCommand,
78
UpdateItemCommand,
@@ -93,15 +94,11 @@ const listMerchItemsResponse = z.object({
9394

9495
const postSchema = z.union([postMerchSchema, postTicketSchema]);
9596

96-
type VerifyPostRequest = z.infer<typeof postSchema>;
97-
98-
type TicketsGetRequest = {
99-
Params: { id: string };
100-
Querystring: { type: string };
101-
Body: undefined;
102-
};
103-
10497
const ticketsPlugin: FastifyPluginAsync = async (fastify, _options) => {
98+
// tickets is legacy and is stuck in us-east-1 for now.
99+
const UsEast1DynamoClient = new DynamoDBClient({
100+
region: "us-east-1",
101+
});
105102
fastify.withTypeProvider<FastifyZodOpenApiTypeProvider>().get(
106103
"",
107104
{
@@ -133,7 +130,7 @@ const ticketsPlugin: FastifyPluginAsync = async (fastify, _options) => {
133130
});
134131

135132
const merchItems: ItemMetadata[] = [];
136-
const response = await fastify.dynamoClient.send(merchCommand);
133+
const response = await UsEast1DynamoClient.send(merchCommand);
137134
const now = new Date();
138135

139136
if (response.Items) {
@@ -168,7 +165,7 @@ const ticketsPlugin: FastifyPluginAsync = async (fastify, _options) => {
168165
});
169166

170167
const ticketItems: TicketItemMetadata[] = [];
171-
const ticketResponse = await fastify.dynamoClient.send(ticketCommand);
168+
const ticketResponse = await UsEast1DynamoClient.send(ticketCommand);
172169

173170
if (ticketResponse.Items) {
174171
for (const item of ticketResponse.Items.map((x) => unmarshall(x))) {
@@ -231,7 +228,7 @@ const ticketsPlugin: FastifyPluginAsync = async (fastify, _options) => {
231228
":itemId": { S: eventId },
232229
},
233230
});
234-
const response = await fastify.dynamoClient.send(command);
231+
const response = await UsEast1DynamoClient.send(command);
235232
if (!response.Items) {
236233
throw new NotFoundError({
237234
endpointName: `/api/v1/tickets/${eventId}`,
@@ -321,7 +318,7 @@ const ticketsPlugin: FastifyPluginAsync = async (fastify, _options) => {
321318
break;
322319
}
323320
try {
324-
await fastify.dynamoClient.send(command);
321+
await UsEast1DynamoClient.send(command);
325322
} catch (e) {
326323
if (e instanceof ConditionalCheckFailedException) {
327324
throw new NotFoundError({
@@ -412,7 +409,7 @@ const ticketsPlugin: FastifyPluginAsync = async (fastify, _options) => {
412409
}
413410
let purchaserData: PurchaseData;
414411
try {
415-
const ticketEntry = await fastify.dynamoClient.send(command);
412+
const ticketEntry = await UsEast1DynamoClient.send(command);
416413
if (!ticketEntry.Attributes) {
417414
throw new DatabaseFetchError({
418415
message: "Could not find ticket data",
@@ -472,7 +469,7 @@ const ticketsPlugin: FastifyPluginAsync = async (fastify, _options) => {
472469
purchaserData,
473470
});
474471
await createAuditLogEntry({
475-
dynamoClient: fastify.dynamoClient,
472+
dynamoClient: UsEast1DynamoClient,
476473
entry: {
477474
module: Modules.TICKETS,
478475
actor: request.username!,

terraform/envs/prod/main.tf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,15 @@ module "archival" {
9696
ProjectId = var.ProjectId
9797
RunEnvironment = "dev"
9898
LogRetentionDays = var.LogRetentionDays
99-
BucketPrefix = local.bucket_prefix
10099
MonitorTables = ["${var.ProjectId}-audit-log", "${var.ProjectId}-events", "${var.ProjectId}-room-requests"]
101100
TableDeletionDays = tomap({
102101
"${var.ProjectId}-audit-log" : 1460,
103102
"${var.ProjectId}-room-requests" : 730
104103
# events are held forever as a cool historical archive - if no one reads them it shouldn't cost us much.
105104
})
105+
providers = {
106+
aws = aws.ohio
107+
}
106108
}
107109

108110
module "lambdas" {

terraform/envs/prod/variables.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ variable "ProjectId" {
1010

1111
variable "GeneralSNSAlertArn" {
1212
type = string
13-
default = "arn:aws:sns:us-east-1:298118738376:infra-monitor-alerts"
13+
default = "arn:aws:sns:us-east-2:298118738376:infra-monitor-alerts"
1414
}
1515

1616
variable "PrioritySNSAlertArn" {
1717
type = string
18-
default = "arn:aws:sns:us-east-1:298118738376:infra-core-api-priority-alerts"
18+
default = "arn:aws:sns:us-east-2:298118738376:infra-core-api-priority-alerts"
1919
}
2020

2121

terraform/envs/qa/main.tf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,16 @@ module "archival" {
9393
ProjectId = var.ProjectId
9494
RunEnvironment = "dev"
9595
LogRetentionDays = var.LogRetentionDays
96-
BucketPrefix = local.bucket_prefix
9796
MonitorTables = ["${var.ProjectId}-audit-log", "${var.ProjectId}-events", "${var.ProjectId}-room-requests"]
9897
TableDeletionDays = tomap({
9998
"${var.ProjectId}-audit-log" : 15,
10099
"${var.ProjectId}-room-requests" : 15
101100
"${var.ProjectId}-events" : 15
102101
// We delete pretty quickly in QA
103102
})
103+
providers = {
104+
aws = aws.ohio
105+
}
104106
}
105107

106108
resource "aws_cloudfront_key_value_store" "linkry_kv" {

terraform/envs/qa/variables.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ variable "EmailDomain" {
4242

4343
variable "GeneralSNSAlertArn" {
4444
type = string
45-
default = "arn:aws:sns:us-east-1:427040638965:infra-monitor-alerts"
45+
default = "arn:aws:sns:us-east-2:427040638965:infra-monitor-alerts"
4646
}
4747

4848
variable "PrioritySNSAlertArn" {
4949
type = string
50-
default = "arn:aws:sns:us-east-1:427040638965:infra-monitor-alerts"
50+
default = "arn:aws:sns:us-east-2:427040638965:infra-monitor-alerts"
5151
}

terraform/modules/alarms/main.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ terraform {
77
}
88

99
resource "aws_cloudwatch_metric_alarm" "app_dlq_messages_alarm" {
10+
region = "us-east-2"
1011
alarm_name = "${var.resource_prefix}-sqs-dlq-present"
1112
alarm_description = "Items are present in the application DLQ, meaning some messages failed to process."
1213
namespace = "AWS/SQS"
@@ -26,6 +27,7 @@ resource "aws_cloudwatch_metric_alarm" "app_dlq_messages_alarm" {
2627
}
2728

2829
resource "aws_cloudwatch_metric_alarm" "app_latency_alarm" {
30+
region = "us-east-2"
2931
for_each = var.performance_noreq_lambdas
3032
alarm_name = "${each.value}-latency-high"
3133
alarm_description = "${replace(each.value, "${var.resource_prefix}-", "")} Trailing Mean - 95% API gateway latency is > 1.5s for 2 times in 4 minutes."
@@ -45,6 +47,7 @@ resource "aws_cloudwatch_metric_alarm" "app_latency_alarm" {
4547
}
4648

4749
resource "aws_cloudwatch_metric_alarm" "app_no_requests_alarm" {
50+
region = "us-east-2"
4851
for_each = var.performance_noreq_lambdas
4952
alarm_name = "${each.value}-no-requests"
5053
alarm_description = "${replace(each.value, "${var.resource_prefix}-", "")}: no requests have been received in the past 5 minutes."
@@ -64,6 +67,7 @@ resource "aws_cloudwatch_metric_alarm" "app_no_requests_alarm" {
6467
}
6568

6669
resource "aws_cloudwatch_metric_alarm" "app_invocation_error_alarm" {
70+
region = "us-east-2"
6771
for_each = var.all_lambdas
6872
alarm_name = "${each.value}-error-invocation"
6973
alarm_description = "${replace(each.value, "${var.resource_prefix}-", "")} lambda threw a critical error."
@@ -83,6 +87,7 @@ resource "aws_cloudwatch_metric_alarm" "app_invocation_error_alarm" {
8387
}
8488

8589
resource "aws_cloudwatch_metric_alarm" "app5xx_error_alarm" {
90+
region = "us-east-2"
8691
alarm_name = "${var.resource_prefix}-cloudfront-5xx-error"
8792
alarm_description = "Main application responses are more than 1% 5xx errors (from Cloudfront)"
8893
namespace = "AWS/CloudFront"
@@ -102,6 +107,7 @@ resource "aws_cloudwatch_metric_alarm" "app5xx_error_alarm" {
102107

103108
# firehose alarms
104109
resource "aws_cloudwatch_metric_alarm" "firehost_archival_data_freshness" {
110+
region = "us-east-2"
105111
alarm_name = "${var.resource_prefix}-firehose-data-stale"
106112
alarm_description = "Delivery of archival records to S3 is taking longer than 5 minutes."
107113
namespace = "AWS/Firehose"

terraform/modules/archival/main.tf

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,40 +5,49 @@ data "archive_file" "api_lambda_code" {
55
}
66

77
locals {
8-
dynamo_stream_reader_lambda_name = "${var.ProjectId}-dynamo-archival"
9-
firehose_stream_name = "${var.ProjectId}-archival-stream"
8+
aws_region = "us-east-2"
9+
dynamo_stream_reader_lambda_name = "${var.ProjectId}-${local.aws_region}-dynamo-archival"
10+
firehose_stream_name = "${var.ProjectId}-${local.aws_region}-archival-stream"
11+
bucket_prefix = "${data.aws_caller_identity.current.account_id}-${local.aws_region}"
1012
}
13+
1114
data "aws_caller_identity" "current" {}
1215
data "aws_region" "current" {}
1316

1417
resource "aws_cloudwatch_log_group" "archive_logs" {
18+
region = local.aws_region
1519
name = "/aws/lambda/${local.dynamo_stream_reader_lambda_name}"
1620
retention_in_days = var.LogRetentionDays
1721
}
1822

1923
resource "aws_cloudwatch_log_group" "firehose_logs" {
24+
region = local.aws_region
2025
name = "/aws/kinesisfirehose/${local.firehose_stream_name}"
2126
retention_in_days = var.LogRetentionDays
2227
}
2328

2429
resource "aws_cloudwatch_log_stream" "firehose_logs_stream" {
30+
region = local.aws_region
2531
log_group_name = aws_cloudwatch_log_group.firehose_logs.name
2632
name = "DataArchivalS3Delivery"
2733
}
2834

2935

3036
resource "aws_s3_bucket" "this" {
31-
bucket = "${var.BucketPrefix}-ddb-archive"
37+
region = local.aws_region
38+
bucket = "${local.bucket_prefix}-ddb-archive"
3239
}
3340

3441
resource "aws_s3_bucket_versioning" "this" {
42+
region = local.aws_region
3543
bucket = aws_s3_bucket.this.id
3644
versioning_configuration {
3745
status = "Enabled"
3846
}
3947
}
4048

4149
resource "aws_s3_bucket_lifecycle_configuration" "this" {
50+
region = local.aws_region
4251
bucket = aws_s3_bucket.this.id
4352

4453
rule {
@@ -92,6 +101,7 @@ resource "aws_s3_bucket_lifecycle_configuration" "this" {
92101
}
93102

94103
resource "aws_s3_bucket_intelligent_tiering_configuration" "this" {
104+
region = local.aws_region
95105
bucket = aws_s3_bucket.this.id
96106
name = "ArchiveAfterSixMonths"
97107
status = "Enabled"
@@ -134,11 +144,13 @@ resource "aws_iam_policy" "archive_lambda_policy" {
134144

135145

136146
data "aws_dynamodb_table" "existing_tables" {
147+
region = local.aws_region
137148
for_each = toset(var.MonitorTables)
138149
name = each.key
139150
}
140151

141152
resource "aws_lambda_event_source_mapping" "stream_mapping" {
153+
region = local.aws_region
142154
for_each = toset(var.MonitorTables)
143155
function_name = aws_lambda_function.api_lambda.arn
144156
event_source_arn = data.aws_dynamodb_table.existing_tables[each.key].stream_arn
@@ -218,6 +230,7 @@ resource "aws_iam_role_policy_attachment" "firehose_attach" {
218230
}
219231

220232
resource "aws_kinesis_firehose_delivery_stream" "dynamic_stream" {
233+
region = local.aws_region
221234
name = local.firehose_stream_name
222235
destination = "extended_s3"
223236

@@ -299,6 +312,7 @@ resource "aws_iam_role_policy_attachment" "archive_attach" {
299312
}
300313

301314
resource "aws_lambda_function" "api_lambda" {
315+
region = local.aws_region
302316
depends_on = [aws_cloudwatch_log_group.archive_logs]
303317
function_name = local.dynamo_stream_reader_lambda_name
304318
role = aws_iam_role.archive_role.arn

terraform/modules/archival/variables.tf

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@ variable "ProjectId" {
33
description = "Prefix before each resource"
44
}
55

6-
variable "BucketPrefix" {
7-
type = string
8-
}
9-
10-
116
variable "LogRetentionDays" {
127
type = number
138
}

terraform/modules/lambdas/main.tf

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,13 +215,15 @@ resource "aws_iam_policy" "shared_iam_policy" {
215215
],
216216
Effect = "Allow",
217217
Resource = [
218+
// Tickets is still in us-east-1!
219+
"arn:aws:dynamodb:us-east-1:${data.aws_caller_identity.current.account_id}:table/infra-events-tickets",
220+
"arn:aws:dynamodb:us-east-1:${data.aws_caller_identity.current.account_id}:table/infra-events-ticketing-metadata",
221+
"arn:aws:dynamodb:us-east-1:${data.aws_caller_identity.current.account_id}:table/infra-merchstore-purchase-history",
222+
"arn:aws:dynamodb:us-east-1:${data.aws_caller_identity.current.account_id}:table/infra-merchstore-purchase-history/index/*",
223+
"arn:aws:dynamodb:us-east-1:${data.aws_caller_identity.current.account_id}:table/infra-merchstore-metadata",
224+
218225
"arn:aws:dynamodb:us-east-2:${data.aws_caller_identity.current.account_id}:table/infra-core-api-events",
219226
"arn:aws:dynamodb:us-east-2:${data.aws_caller_identity.current.account_id}:table/infra-core-api-events/index/*",
220-
"arn:aws:dynamodb:us-east-2:${data.aws_caller_identity.current.account_id}:table/infra-merchstore-purchase-history",
221-
"arn:aws:dynamodb:us-east-2:${data.aws_caller_identity.current.account_id}:table/infra-merchstore-purchase-history/index/*",
222-
"arn:aws:dynamodb:us-east-2:${data.aws_caller_identity.current.account_id}:table/infra-events-tickets",
223-
"arn:aws:dynamodb:us-east-2:${data.aws_caller_identity.current.account_id}:table/infra-events-ticketing-metadata",
224-
"arn:aws:dynamodb:us-east-2:${data.aws_caller_identity.current.account_id}:table/infra-merchstore-metadata",
225227
"arn:aws:dynamodb:us-east-2:${data.aws_caller_identity.current.account_id}:table/infra-core-api-iam-assignments",
226228
"arn:aws:dynamodb:us-east-2:${data.aws_caller_identity.current.account_id}:table/infra-core-api-stripe-links",
227229
"arn:aws:dynamodb:us-east-2:${data.aws_caller_identity.current.account_id}:table/infra-core-api-stripe-links/index/*",

0 commit comments

Comments
 (0)