This repository has been archived by the owner on Sep 18, 2023. It is now read-only.
forked from buoyant-data/oxbow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deployment.tf
170 lines (144 loc) · 3.98 KB
/
deployment.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
159
160
161
162
163
164
165
166
167
168
169
170
# This Terraform file is necessary to configure the basic
# infrastructure around the Optimize lambda function
resource "aws_lambda_function" "oxbow" {
description = "A simple lambda for converting parquet files to delta tables"
filename = "target/lambda/oxbow-lambda/bootstrap.zip"
function_name = "oxbow-conversion"
role = aws_iam_role.iam_for_lambda.arn
handler = "provided"
runtime = "provided.al2"
environment {
variables = {
AWS_S3_LOCKING_PROVIDER = "dynamodb"
RUST_LOG = "deltalake=debug,oxbow=debug"
DYNAMO_LOCK_TABLE_NAME = aws_dynamodb_table.oxbow_locking.name
}
}
}
resource "aws_lambda_event_source_mapping" "oxbow-trigger" {
event_source_arn = aws_sqs_queue.oxbow.arn
function_name = aws_lambda_function.oxbow.arn
}
resource "aws_sqs_queue" "oxbow" {
name = "oxbow-notification-queue"
policy = data.aws_iam_policy_document.queue.json
}
resource "aws_s3_bucket" "parquets" {
bucket = "oxbow-dev-parquet"
}
resource "aws_lambda_permission" "allow_bucket" {
statement_id = "AllowExecutionFromS3Bucket"
action = "lambda:InvokeFunction"
function_name = aws_lambda_function.oxbow.arn
principal = "s3.amazonaws.com"
source_arn = aws_s3_bucket.parquets.arn
}
resource "aws_s3_bucket_notification" "bucket_notification" {
bucket = aws_s3_bucket.parquets.id
queue {
queue_arn = aws_sqs_queue.oxbow.arn
events = ["s3:ObjectCreated:*"]
filter_suffix = ".parquet"
}
depends_on = [aws_lambda_permission.allow_bucket]
}
data "aws_iam_policy_document" "assume_role" {
statement {
effect = "Allow"
principals {
type = "Service"
identifiers = ["lambda.amazonaws.com"]
}
actions = [
"sts:AssumeRole",
]
}
}
resource "aws_iam_policy" "lambda_permissions" {
name = "oxbow-permissions"
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = ["dynamodb:*"]
Resource = aws_dynamodb_table.oxbow_locking.arn
Effect = "Allow"
},
{
Action = ["s3:*"]
Resource = var.s3_bucket_arn
Effect = "Allow"
},
{
Action = ["sqs:*"]
Resource = aws_sqs_queue.oxbow.arn
Effect = "Allow"
}
]
})
}
data "aws_iam_policy_document" "queue" {
statement {
effect = "Allow"
principals {
type = "*"
identifiers = ["*"]
}
actions = ["sqs:SendMessage"]
# Hard-coding an ARN like syntax here because of the dependency cycle
resources = ["arn:aws:sqs:*:*:oxbow-notification-queue"]
condition {
test = "ArnEquals"
variable = "aws:SourceArn"
values = [aws_s3_bucket.parquets.arn]
}
}
}
resource "aws_iam_role" "iam_for_lambda" {
name = "iam_for_oxbow_lambda"
assume_role_policy = data.aws_iam_policy_document.assume_role.json
managed_policy_arns = [
aws_iam_policy.lambda_permissions.arn,
"arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole",
]
}
# The DynamoDb table is used for providing safe concurrent writes to delta
# tables.
resource "aws_dynamodb_table" "oxbow_locking" {
name = "oxbow_lock_table"
billing_mode = "PROVISIONED"
# Default name of the partition key hard-coded in delta-rs
hash_key = "key"
read_capacity = 10
write_capacity = 10
attribute {
name = "key"
type = "S"
}
}
### Bootstrapping/configuration
variable "s3_bucket_arn" {
type = string
default = "*"
description = "The ARN for the S3 bucket that the optimize function will optimize"
}
variable "aws_access_key" {
type = string
default = ""
}
variable "aws_secret_key" {
type = string
default = ""
}
provider "aws" {
region = "us-west-2"
access_key = var.aws_access_key
secret_key = var.aws_secret_key
default_tags {
tags = {
ManagedBy = "Terraform"
environment = terraform.workspace
workspace = terraform.workspace
}
}
}