-
Notifications
You must be signed in to change notification settings - Fork 2
/
awsiiifs3batch.template
259 lines (259 loc) · 6.9 KB
/
awsiiifs3batch.template
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
AWSTemplateFormatVersion: '2010-09-09'
Description: Orchestrating an Application Process with AWS Batch using CloudFormation
Parameters:
DockerImage:
Description: Docker image or a repository from a registry
Default: wlhunter/iiif_s3_tiling:latest
Type: String
JDName:
Description: Job definition name
Default: IIIFS3JobDefinition
Type: String
JQName:
Description: Job queue name
Default: IIIFS3JobQueue
Type: String
LambdaRoleName:
Description: Lambda role name
Default: lambda-role
Type: String
LambdaFunctionName:
Description: Lambda function name
Default: BatchProcessingLambdaInvokeFunction
Type: String
BatchRepositoryName:
Description: Batch process repository name
Default: batch-processing-job-repository
Type: String
S3BucketName:
Description: S3 bucket name
Default: vtdlp-tiling-batch-deposit
Type: String
Resources:
VPC:
Type: AWS::EC2::VPC
Properties:
CidrBlock: 10.0.0.0/16
InternetGateway:
Type: AWS::EC2::InternetGateway
RouteTable:
Type: AWS::EC2::RouteTable
Properties:
VpcId:
Ref: VPC
VPCGatewayAttachment:
Type: AWS::EC2::VPCGatewayAttachment
Properties:
VpcId:
Ref: VPC
InternetGatewayId:
Ref: InternetGateway
SecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: EC2 Security Group for instances launched in the VPC by Batch
VpcId:
Ref: VPC
Subnet:
Type: AWS::EC2::Subnet
Properties:
AvailabilityZone: us-east-1a
CidrBlock: 10.0.0.0/24
VpcId:
Ref: VPC
MapPublicIpOnLaunch: 'True'
Route:
Type: AWS::EC2::Route
Properties:
RouteTableId:
Ref: RouteTable
DestinationCidrBlock: 0.0.0.0/0
GatewayId:
Ref: InternetGateway
SubnetRouteTableAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
RouteTableId:
Ref: RouteTable
SubnetId:
Ref: Subnet
LambdaExecutionRole:
Type: AWS::IAM::Role
Properties:
RoleName:
Fn::Sub: ${LambdaRoleName}
AssumeRolePolicyDocument:
Statement:
- Action:
- sts:AssumeRole
Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Version: 2012-10-17
ManagedPolicyArns:
- arn:aws:iam::aws:policy/AWSLambdaExecute
- arn:aws:iam::aws:policy/AmazonS3FullAccess
- arn:aws:iam::aws:policy/AWSBatchFullAccess
- arn:aws:iam::aws:policy/service-role/AWSBatchServiceRole
Path: /
BatchServiceRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service: batch.amazonaws.com
Action: sts:AssumeRole
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AWSBatchServiceRole
IamInstanceProfile:
Type: AWS::IAM::InstanceProfile
Properties:
Roles:
- Ref: EcsInstanceRole
EcsInstanceRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2008-10-17'
Statement:
- Sid: ''
Effect: Allow
Principal:
Service: ec2.amazonaws.com
Action: sts:AssumeRole
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AmazonEC2ContainerServiceforEC2Role
- arn:aws:iam::aws:policy/AmazonS3FullAccess
BatchProcessingJobDefinition:
Type: AWS::Batch::JobDefinition
Properties:
Type: container
JobDefinitionName:
Ref: JDName
ContainerProperties:
Image:
Ref: DockerImage
ResourceRequirements:
- Type: MEMORY
Value: '10854'
- Type: VCPU
Value: '4'
Command:
- ./createiiif.sh
RetryStrategy:
Attempts: 1
BatchProcessingJobQueue:
Type: AWS::Batch::JobQueue
Properties:
JobQueueName:
Ref: JQName
Priority: 1
ComputeEnvironmentOrder:
- Order: 1
ComputeEnvironment:
Ref: ComputeEnvironment
ComputeEnvironment:
Type: AWS::Batch::ComputeEnvironment
Properties:
Type: MANAGED
ComputeResources:
Type: EC2
MinvCpus: 0
DesiredvCpus: 48
MaxvCpus: 48
InstanceTypes:
- c5a.12xlarge
Subnets:
- Ref: Subnet
SecurityGroupIds:
- Ref: SecurityGroup
InstanceRole:
Ref: IamInstanceProfile
LaunchTemplate:
LaunchTemplateName: increase-tilng-storage
Version: '1'
ServiceRole:
Ref: BatchServiceRole
BatchProcessS3Bucket:
Type: AWS::S3::Bucket
DependsOn: BatchProcessBucketPermission
Properties:
BucketName:
Fn::Sub: ${S3BucketName}-${AWS::AccountId}
NotificationConfiguration:
LambdaConfigurations:
- Event: s3:ObjectCreated:*
Function:
Fn::GetAtt:
- BatchProcessingLambdaInvokeFunction
- Arn
BatchProcessBucketPermission:
Type: AWS::Lambda::Permission
Properties:
Action: lambda:InvokeFunction
FunctionName:
Ref: BatchProcessingLambdaInvokeFunction
Principal: s3.amazonaws.com
SourceAccount:
Ref: AWS::AccountId
SourceArn:
Fn::Sub: arn:aws:s3:::${S3BucketName}-${AWS::AccountId}
BatchProcessingLambdaInvokeFunction:
Type: AWS::Lambda::Function
Properties:
FunctionName:
Ref: LambdaFunctionName
Description: Python Function Handler that would be triggered BY s3 events TO
the aws batch
Handler: index.lambda_handler
Runtime: python3.9
MemorySize: 128
Timeout: 30
Role:
Fn::GetAtt:
- LambdaExecutionRole
- Arn
Code:
S3Bucket: vtlib-cf-template
S3Key: dev/lambda-scripts/aws-batch-iiif-generator/20240118/e8d3b3d262ee42e5b3986d95645528ca
BatchProcessRepository:
Type: AWS::ECR::Repository
Properties:
RepositoryName:
Ref: BatchRepositoryName
RepositoryPolicyText:
Version: '2012-10-17'
Statement:
- Sid: AllowPushPull
Effect: Allow
Principal:
AWS:
- Fn::Sub: arn:aws:iam::${AWS::AccountId}:role/${EcsInstanceRole}
Action:
- ecr:GetDownloadUrlForLayer
- ecr:BatchGetImage
- ecr:BatchCheckLayerAvailability
- ecr:PutImage
- ecr:InitiateLayerUpload
- ecr:UploadLayerPart
- ecr:CompleteLayerUpload
Outputs:
ComputeEnvironmentArn:
Value:
Ref: ComputeEnvironment
BatchProcessingJobQueueArn:
Value:
Ref: BatchProcessingJobQueue
BatchProcessingJobDefinitionArn:
Value:
Ref: BatchProcessingJobDefinition
BucketName:
Value:
Ref: BatchProcessS3Bucket
LambdaName:
Value:
Ref: BatchProcessingLambdaInvokeFunction