Skip to content

Commit dbc9894

Browse files
committed
add : aws glue catalog table with storage and ser_de configuration
1 parent 95dee67 commit dbc9894

File tree

3 files changed

+196
-0
lines changed

3 files changed

+196
-0
lines changed

locals.tf

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,156 @@
11
locals {
22
query_results_bucket_location = "s3://${var.query_results_bucket}/output/"
3+
alb_logs_bucket_location = "s3://${var.s3_bucket_name}/${var.s3_log_prefix}"
4+
input_format = "org.apache.hadoop.mapred.TextInputFormat"
5+
output_format = "org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat"
6+
ser_de_name = "alb-logs-serde"
7+
ser_de_library = "org.apache.hadoop.hive.serde2.RegexSerDe"
8+
ser_de_parameters = {
9+
"serialization.format" = "1"
10+
"input.regex" = "([^ ]*) ([^ ]*) ([^ ]*) ([^ ]*):([0-9]*) ([^ ]*)[:-]([0-9]*) ([-.0-9]*) ([-.0-9]*) ([-.0-9]*) (|[-0-9]*) (-|[-0-9]*) ([-0-9]*) ([-0-9]*) \"([^ ]*) (.*) (- |[^ ]*)\" \"([^\"]*)\" ([A-Z0-9-_]+) ([A-Za-z0-9.-]*) ([^ ]*) \"([^\"]*)\" \"([^\"]*)\" \"([^\"]*)\" ([-.0-9]*) ([^ ]*) \"([^\"]*)\" \"([^\"]*)\" \"([^ ]*)\" \"([^\\s]+?)\" \"([^\\s]+)\" \"([^ ]*)\" \"([^ ]*)\" ?([^ ]*)?"
11+
}
12+
table_type = "EXTERNAL_TABLE"
13+
parameters = {
14+
"classification" = "log"
15+
"typeOfData" = "awsALBLogs"
16+
}
17+
18+
table_columns = [
19+
{
20+
name = "type"
21+
type = "string"
22+
},
23+
{
24+
name = "time"
25+
type = "string"
26+
},
27+
{
28+
name = "elb"
29+
type = "string"
30+
},
31+
{
32+
name = "client_ip"
33+
type = "string"
34+
},
35+
{
36+
name = "client_port"
37+
type = "int"
38+
},
39+
{
40+
name = "target_ip"
41+
type = "string"
42+
},
43+
{
44+
name = "target_port"
45+
type = "int"
46+
},
47+
{
48+
name = "request_processing_time"
49+
type = "double"
50+
},
51+
{
52+
name = "target_processing_time"
53+
type = "double"
54+
},
55+
{
56+
name = "response_processing_time"
57+
type = "double"
58+
},
59+
{
60+
name = "elb_status_code"
61+
type = "int"
62+
},
63+
{
64+
name = "target_status_code"
65+
type = "string"
66+
},
67+
{
68+
name = "received_bytes"
69+
type = "bigint"
70+
},
71+
{
72+
name = "sent_bytes"
73+
type = "bigint"
74+
},
75+
{
76+
name = "request_verb"
77+
type = "string"
78+
},
79+
{
80+
name = "request_url"
81+
type = "string"
82+
},
83+
{
84+
name = "request_proto"
85+
type = "string"
86+
},
87+
{
88+
name = "user_agent"
89+
type = "string"
90+
},
91+
{
92+
name = "ssl_cipher"
93+
type = "string"
94+
},
95+
{
96+
name = "ssl_protocol"
97+
type = "string"
98+
},
99+
{
100+
name = "target_group_arn"
101+
type = "string"
102+
},
103+
{
104+
name = "trace_id"
105+
type = "string"
106+
},
107+
{
108+
name = "domain_name"
109+
type = "string"
110+
},
111+
{
112+
name = "chosen_cert_arn"
113+
type = "string"
114+
},
115+
{
116+
name = "matched_rule_priority"
117+
type = "string"
118+
},
119+
{
120+
name = "request_creation_time"
121+
type = "string"
122+
},
123+
{
124+
name = "actions_executed"
125+
type = "string"
126+
},
127+
{
128+
name = "redirect_url"
129+
type = "string"
130+
},
131+
{
132+
name = "lambda_error_reason"
133+
type = "string"
134+
},
135+
{
136+
name = "target_port_list"
137+
type = "string"
138+
},
139+
{
140+
name = "target_status_code_list"
141+
type = "string"
142+
},
143+
{
144+
name = "classification"
145+
type = "string"
146+
},
147+
{
148+
name = "classification_reason"
149+
type = "string"
150+
},
151+
{
152+
name = "conn_trace_id"
153+
type = "string"
154+
}
155+
]
3156
}

main.tf

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,31 @@ resource "aws_athena_workgroup" "this" {
1414
resource "aws_glue_catalog_database" "this" {
1515
name = var.database_name
1616
}
17+
18+
resource "aws_glue_catalog_table" "this" {
19+
name = var.table_name
20+
database_name = aws_glue_catalog_database.this.name
21+
table_type = local.table_type
22+
parameters = local.parameters
23+
24+
storage_descriptor {
25+
location = local.alb_logs_bucket_location
26+
input_format = local.input_format
27+
output_format = local.output_format
28+
29+
ser_de_info {
30+
name = local.ser_de_name
31+
serialization_library = local.ser_de_library
32+
33+
parameters = local.ser_de_parameters
34+
}
35+
36+
dynamic "columns" {
37+
for_each = local.table_columns
38+
content {
39+
name = columns.value.name
40+
type = columns.value.type
41+
}
42+
}
43+
}
44+
}

variables.tf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,18 @@ variable "database_name" {
1212
description = "The name of the Athena database."
1313
type = string
1414
}
15+
16+
variable "table_name" {
17+
description = "The name of the Athena table to query ALB logs."
18+
type = string
19+
}
20+
21+
variable "s3_bucket_name" {
22+
description = "The name of the S3 bucket where ALB logs are stored."
23+
type = string
24+
}
25+
26+
variable "s3_log_prefix" {
27+
description = "The prefix within the S3 bucket where ALB logs are stored (e.g., 'AWSLogs/')."
28+
type = string
29+
}

0 commit comments

Comments
 (0)