Skip to content

Commit df7f2fc

Browse files
authored
[PRMP-570] Step Function Error Handling (#486)
1 parent 1156c3f commit df7f2fc

File tree

4 files changed

+50
-11
lines changed

4 files changed

+50
-11
lines changed

infrastructure/buckets.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,18 @@ module "migration-dynamodb-segment-store" {
8585
force_destroy = local.is_force_destroy
8686
}
8787

88+
module "migration-failed-items-store" {
89+
source = "./modules/s3/"
90+
access_logs_enabled = local.is_production
91+
access_logs_bucket_id = local.access_logs_bucket_id
92+
bucket_name = var.migration_failed_items_store_bucket_name
93+
enable_cors_configuration = false
94+
enable_bucket_versioning = true
95+
environment = var.environment
96+
owner = var.owner
97+
force_destroy = local.is_force_destroy
98+
}
99+
88100
module "statistical-reports-store" {
89101
source = "./modules/s3/"
90102
access_logs_enabled = local.is_production

infrastructure/lambda-dynamodb-migration.tf

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ module "migration-dynamodb-lambda" {
1010
module.ndr-bulk-staging-store.s3_read_policy_document,
1111
module.ndr-lloyd-george-store.s3_read_policy_document,
1212
aws_iam_policy.ssm_access_policy.policy,
13-
module.ndr-app-config.app_config_policy
13+
module.ndr-app-config.app_config_policy,
14+
module.migration-failed-items-store.s3_write_policy_document
1415
]
1516

1617
kms_deletion_window = var.kms_deletion_window
@@ -20,10 +21,11 @@ module "migration-dynamodb-lambda" {
2021
is_invoked_from_gateway = false
2122

2223
lambda_environment_variables = {
23-
WORKSPACE = terraform.workspace
24-
APPCONFIG_APPLICATION = module.ndr-app-config.app_config_application_id
25-
APPCONFIG_ENVIRONMENT = module.ndr-app-config.app_config_environment_id
26-
APPCONFIG_CONFIGURATION = module.ndr-app-config.app_config_configuration_profile_id
24+
WORKSPACE = terraform.workspace
25+
APPCONFIG_APPLICATION = module.ndr-app-config.app_config_application_id
26+
APPCONFIG_ENVIRONMENT = module.ndr-app-config.app_config_environment_id
27+
APPCONFIG_CONFIGURATION = module.ndr-app-config.app_config_configuration_profile_id
28+
MIGRATION_FAILED_ITEMS_STORE_BUCKET_NAME = "${terraform.workspace}-${var.migration_failed_items_store_bucket_name}"
2729
}
2830

2931
lambda_timeout = 900
@@ -35,5 +37,6 @@ module "migration-dynamodb-lambda" {
3537
module.bulk_upload_report_dynamodb_table,
3638
module.ndr-app-config,
3739
aws_iam_policy.ssm_access_policy,
40+
module.migration-failed-items-store
3841
]
3942
}

infrastructure/step-function-migration-dynmodb.tf

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,17 @@ resource "aws_sfn_state_machine" "migration_dynamodb" {
116116
"key.$" = "$.Payload.key"
117117
},
118118
ResultPath = "$.SegmentSource",
119-
Next = "Segment Map (Distributed)"
119+
Next = "Segment Map (Distributed)",
120+
121+
Retry = [
122+
{
123+
ErrorEquals = ["States.ALL"]
124+
IntervalSeconds = 2
125+
MaxAttempts = 3
126+
BackoffRate = 2.0
127+
JitterStrategy = "FULL"
128+
}
129+
]
120130
},
121131

122132
"Segment Map (Distributed)" = {
@@ -139,8 +149,8 @@ resource "aws_sfn_state_machine" "migration_dynamodb" {
139149
"totalSegments.$" = "$.totalSegments",
140150
"tableArn.$" = "$.tableArn",
141151
"migrationScript.$" = "$.migrationScript",
142-
"run_migration.$" = "$.run_migration",
143-
"execution_Id.$" = "$$.Execution.Id"
152+
"runMigration.$" = "$.runMigration",
153+
"executionId.$" = "$$.Execution.Id"
144154
},
145155

146156
ItemProcessor = {
@@ -160,13 +170,22 @@ resource "aws_sfn_state_machine" "migration_dynamodb" {
160170
"totalSegments.$" = "$.totalSegments",
161171
"tableArn.$" = "$.tableArn",
162172
"migrationScript.$" = "$.migrationScript",
163-
"run_migration.$" = "$.run_migration",
164-
"execution_Id.$" = "$.execution_Id"
173+
"runMigration.$" = "$.runMigration",
174+
"executionId.$" = "$.executionId"
165175
}
166176
},
167177
ResultSelector = { "migrationResult.$" = "$.Payload" },
168178
ResultPath = "$.MigrationResult",
169-
End = true
179+
End = true,
180+
Retry = [
181+
{
182+
ErrorEquals = ["States.ALL"]
183+
IntervalSeconds = 10
184+
MaxAttempts = 3
185+
BackoffRate = 2.0
186+
JitterStrategy = "FULL"
187+
}
188+
]
170189
}
171190
}
172191
},

infrastructure/variable.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ variable "migration_dynamodb_segment_store_bucket_name" {
3939
default = "migration-dynamodb-segment-store"
4040
}
4141

42+
variable "migration_failed_items_store_bucket_name" {
43+
description = "The name of the S3 bucket to store failed items during DynamoDB migration."
44+
type = string
45+
default = "migration-failed-items-store"
46+
}
4247
variable "zip_store_bucket_name" {
4348
description = "The name of the S3 bucket used as a zip store."
4449
type = string

0 commit comments

Comments
 (0)