-
Notifications
You must be signed in to change notification settings - Fork 0
/
sfn.tf
158 lines (156 loc) · 4.87 KB
/
sfn.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
provider "aws" {
region = "us-west-1" # Change to your desired AWS region
}
resource "aws_sfn_state_machine" "example_state_machine" {
name = "MyStateMachine"
role_arn = "arn:aws:iam::123456789012:role/step-functions-role" # Replace with your IAM role ARN
definition = <<EOF
{
"StartAt": "glue-task",
"States": {
"glue-task": {
"Next": "postupdate-task",
"Retry": [
{
"ErrorEquals": ["States.ALL"],
"MaxAttempts": 1
}
],
"Catch": [
{
"ErrorEquals": ["States.ALL"],
"ResultPath": "$.ErrorMessage",
"Next": "error-task"
}
],
"Type": "Task",
"ResultPath": null,
"Resource": "arn:aws:states:::glue:startJobRun.sync",
"Parameters": {
"JobName": "glue_uw1_da099_mfgottestperm_standardization_ddkdatadev",
"Arguments": {
"--DATASET.$": "$.body.dataset",
"--PEH_ID.$": "$.body.peh_id",
"--SOURCE_TYPE": "flat_file_json",
"--SOURCE_LOCATIONS_LIST_S3_LOC.$": "$.body.source_locations_list_s3_loc",
"--SOURCE_APP_PREPROCESS": "N",
"--SOURCE_APP_PREPROCESS_TYPE": "NA",
"--SOURCE_APP_POSTPROCESS": "N",
"--SOURCE_APP_POSTPROCESS_TYPE": "N",
"--SOURCE_DATA_QUALITY": "N",
"--SOURCE_FILE_COMPRESSION": "N",
"--SOURCE_FILE_FORMAT": "ndjson",
"--SOURCE_FILE_DELIMITER": "",
"--SOURCE_INFER_SCHEMA": "Y",
"--USE_SQS": "N",
"--DATASET_LEVEL": "2",
"--TARGET_LOCATION": "s3a://ddkdatadev-****-poc-standardized-usw1/mfg_ot_test_perm/",
"--TARGET_FILE_FORMAT": "parquet",
"--TARGET_PARTITION_KEY": "N",
"--TARGET_PRIMARY_KEY": "",
"--TARGET_APPEND_FLAG": "N",
"--TARGET_CATALOG_DB_NAME": "ddk_ot_test_perm_stdd_data",
"--DATA_PIPELINE_JOB_ID": "da099",
"--SCHEDULE_TYPE": "time_based",
"--SCHEDULE_MIN": "15",
"--FILE_BATCH_SIZE": "5000",
"--MAX_SFN_INVOCATIONS": "1",
"--ENVIRONMENT": "QAS",
"--APPLICATION": "POC",
"--DIVISION": "Shared Services",
"--PROJECT_ID": "ddkdatadev",
"--BUSINESS_OWNER": "",
"--L1_TECHNICAL_OWNER": "mureddy@amazon.com",
"--COST_CENTER": "",
"--FUNCTIONS": "POC",
"--conf": "spark.hadoop.fs.s3a.server-side-encryption-algorithm=AES256"
},
"Timeout": 60,
"NotificationProperty": {
"NotifyDelayAfter": 5
}
}
},
"postupdate-task": {
"Next": "crawl-task",
"Retry": [
{
"ErrorEquals": ["Lambda.ServiceException", "Lambda.AWSLambdaException", "Lambda.SdkClientException"],
"IntervalSeconds": 2,
"MaxAttempts": 6,
"BackoffRate": 2
}
],
"Type": "Task",
"Resource": "arn:aws:states:::lambda:invoke",
"Parameters": {
"FunctionName": "arn:aws:lambda:us-west-1:****:function:lambda_uw1_da099_mfgottestperm_postupdate_ddkdatadev",
"Payload": {
"body.$": "$.body",
"status": "COMPLETED"
}
}
},
"crawl-task": {
"Next": "success",
"Catch": [
{
"ErrorEquals": ["Glue.CrawlerRunningException"],
"ResultPath": null,
"Next": "success"
}
],
"Type": "Task",
"ResultPath": null,
"Resource": "arn:aws:states:::aws-sdk:glue:startCrawler",
"Parameters": {
"Name": "crawl_uw1_da099_mfgottestperm_standardization_ddkdatadev"
}
},
"success": {
"Type": "Succeed"
},
"error-task": {
"Next": "error-notification",
"Retry": [
{
"ErrorEquals": ["Lambda.ServiceException", "Lambda.AWSLambdaException", "Lambda.SdkClientException"],
"IntervalSeconds": 2,
"MaxAttempts": 6,
"BackoffRate": 2
}
],
"Type": "Task",
"Resource": "arn:aws:states:::lambda:invoke",
"Parameters": {
"FunctionName": "arn:aws:lambda:us-west-1:****:function:lambda_uw1_da099_mfgottestperm_postupdate_ddkdatadev",
"Payload": {
"body.$": "$.body",
"error.$": "States.StringToJson($.ErrorMessage.Cause)",
"status": "FAILED"
}
}
},
"error-notification": {
"Next": "failed",
"Type": "Task",
"Resource": "arn:aws:states:::sns:publish",
"Parameters": {
"TopicArn": "arn:aws:sns:us-west-1:****:sns_uw1_da099_mfgottestperm_failures_ddkdatadev",
"Message": {
"ErrorMessage.$": "$.Payload.error.ErrorMessage",
"PipelineExecution.$": "$.Payload.body.peh_id",
"Environment.$": "$.Payload.body.environment"
}
}
},
"failed": {
"Type": "Fail"
}
}
}
EOF
}
output "state_machine_arn" {
value = aws_sfn_state_machine.example_state_machine.arn
}