Skip to content

Commit

Permalink
Production deployment (#251)
Browse files Browse the repository at this point in the history
**Only merge using a merge commit!**
  • Loading branch information
github-actions[bot] authored Feb 8, 2024
2 parents 0f929aa + c66b15f commit ff95826
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 87 deletions.
70 changes: 45 additions & 25 deletions app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"dependencies": {
"@algolia/autocomplete-js": "1.15.1",
"@algolia/autocomplete-theme-classic": "1.15.1",
"@aws-sdk/client-s3": "3.502.0",
"@aws-sdk/s3-request-presigner": "3.502.0",
"@aws-sdk/client-s3": "3.503.1",
"@aws-sdk/s3-request-presigner": "3.503.1",
"@next-auth/prisma-adapter": "1.0.7",
"@paralleldrive/cuid2": "2.2.2",
"@prisma/client": "5.9.0",
Expand Down Expand Up @@ -55,7 +55,7 @@
"@tailwindcss/typography": "0.5.10",
"@types/eslint": "8.56.2",
"@types/lodash": "4.14.202",
"@types/node": "18.19.10",
"@types/node": "18.19.11",
"@types/prettier": "3.0.0",
"@types/react": "18.2.48",
"@types/react-dom": "18.2.18",
Expand Down
3 changes: 3 additions & 0 deletions cloudformation/setup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ Resources:
- config:DescribeConfigurationRecorders
- config:DescribeDeliveryChannels
- events:DescribeEventBus
- events:DescribeRule
- events:ListTagsForResource
- events:ListTargetsByRule
- iam:GetOpenIDConnectProvider
- iam:GetRole
- iam:GetRolePolicy
Expand All @@ -91,6 +93,7 @@ Resources:
- kms:ListAliases
- lambda:GetFunction
- lambda:GetFunctionCodeSigningConfig
- lambda:GetPolicy
- lambda:ListVersionsByFunction
- logs:DescribeLogGroups
- logs:ListTagsLogGroup
Expand Down
8 changes: 4 additions & 4 deletions email-function/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion email-function/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"@types/node": "20.10.2",
"dotenv": "16.4.1",
"form-data": "4.0.0",
"mailgun.js": "10.0.1",
"mailgun.js": "10.1.0",
"openpgp": "5.11.0",
"serialize-error": "11.0.3",
"zod": "3.22.4"
Expand Down
2 changes: 2 additions & 0 deletions email-function/src/lambda-eventbridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export const handler: EventBridgeHandler<DetailType, Detail, Result> = async (ev
log.error("errorHandler", {
error: serializeError(error),
});

throw error;
}
};

Expand Down
75 changes: 46 additions & 29 deletions terraform/cloudwatch.tf
Original file line number Diff line number Diff line change
@@ -1,39 +1,56 @@
# Related: https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Best_Practice_Recommended_Alarms_AWS_Services.html

resource "aws_cloudwatch_metric_alarm" "api_gateway_5xx_error" {
alarm_name = "api-gateway-5xx-error"

namespace = "AWS/ApiGateway"
metric_name = "5XXError"
# Related: https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-metrics-and-dimensions.html
dimensions = {
ApiName = aws_api_gateway_rest_api.main.name
}

statistic = "Sum"
comparison_operator = "GreaterThanOrEqualToThreshold"
threshold = 1
evaluation_periods = 1
datapoints_to_alarm = 1
period = 60
alarm_description = "This alarm helps to detect a high rate of server-side errors. This can indicate that there is something wrong on the API backend, the network, or the integration between the API gateway and the backend API."

alarm_actions = []
alarm_name = "api-gateway-5xx-error"

namespace = "AWS/ApiGateway"
metric_name = "5XXError"
# Related: https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-metrics-and-dimensions.html
dimensions = {
ApiName = aws_api_gateway_rest_api.main.name
}

statistic = "Sum"
comparison_operator = "GreaterThanOrEqualToThreshold"
threshold = 1
evaluation_periods = 1
datapoints_to_alarm = 1
period = 60
alarm_description = "This alarm helps to detect a high rate of 500er responses in any API Gateway."

alarm_actions = []
}

resource "aws_cloudwatch_metric_alarm" "lambda_throttles" {
alarm_name = "lambda-throttles"
alarm_name = "lambda-throttles"

namespace = "AWS/Lambda"
metric_name = "Throttles"
namespace = "AWS/Lambda"
metric_name = "Throttles"

statistic = "Sum"
comparison_operator = "GreaterThanOrEqualToThreshold"
threshold = 1
evaluation_periods = 1
datapoints_to_alarm = 1
period = 60
alarm_description = "This alarm detects a high number of throttled invocation requests. Throttling occurs when there is no concurrency is available for scale up. There are several approaches to resolve this issue. 1) Request a concurrency increase from AWS Support in this Region. 2) Identify performance issues in the function to improve the speed of processing and therefore improve throughput. 3) Increase the batch size of the function, so that more messages are processed by each function invocation."
statistic = "Sum"
comparison_operator = "GreaterThanOrEqualToThreshold"
threshold = 1
evaluation_periods = 1
datapoints_to_alarm = 1
period = 60
alarm_description = "This alarm detects a high number of throttled invocation requests for any Lambda function."

alarm_actions = []
alarm_actions = []
}

resource "aws_cloudwatch_metric_alarm" "lambda_errors" {
alarm_name = "lambda-errors"

namespace = "AWS/Lambda"
metric_name = "Errors"

statistic = "Sum"
comparison_operator = "GreaterThanOrEqualToThreshold"
threshold = 1
evaluation_periods = 1
datapoints_to_alarm = 1
period = 60
alarm_description = "This alarm detects a high number of errors for any Lambda function."

alarm_actions = []
}
44 changes: 19 additions & 25 deletions terraform/modules/api-gateway-eventbridge-lambda/eventbridge.tf
Original file line number Diff line number Diff line change
@@ -1,28 +1,22 @@
# resource "aws_cloudwatch_event_rule" "main" {
# event_bus_name = var.event_bus.arn
resource "aws_cloudwatch_event_rule" "main" {
event_bus_name = var.event_bus.arn

# event_pattern = jsonencode({
# detail-type = [
# var.event_bus_detail_type
# ]
# })
event_pattern = jsonencode({
detail-type = [
var.event_bus_detail_type
]
})
}

# # TODO
# # role_arn = ""
# }
resource "aws_cloudwatch_event_target" "main" {
rule = aws_cloudwatch_event_rule.main.name
arn = aws_lambda_function.main.arn
event_bus_name = var.event_bus.arn
}

# resource "aws_cloudwatch_event_target" "main" {
# rule = aws_cloudwatch_event_rule.main.name
# arn = aws_lambda_function.main.arn
# event_bus_name = var.event_bus.arn

# run_command_targets {
# key = "tag:Name"
# values = ["FooBar"]
# }

# run_command_targets {
# key = "InstanceIds"
# values = ["i-162058cd308bffec2"]
# }
# }
resource "aws_lambda_permission" "api_gateway" {
action = "lambda:InvokeFunction"
function_name = aws_lambda_function.main.function_name
principal = "events.amazonaws.com"
source_arn = aws_cloudwatch_event_rule.main.arn
}

0 comments on commit ff95826

Please sign in to comment.