-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomprehend-semi-structured-documents-annotation-template.yml
209 lines (192 loc) · 6.73 KB
/
comprehend-semi-structured-documents-annotation-template.yml
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
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Metadata:
AWS::ServerlessRepo::Application:
Name: ComprehendSemiStructuredDocumentsAnnotationLambda
Description: Deploys a Lambda which create resources to start GT SemiStructured Documents labeling job.
Author: AWS Comprehend
ReadmeUrl: README.md
Labels: [serverless]
HomePageUrl: https://aws.amazon.com/comprehend/
SemanticVersion: 1.0.0
SourceCodeUrl: https://github.com/aws-samples/amazon-comprehend-examples
Parameters:
PreHumanLambdaTimeoutInSeconds:
Type: Number
Default: 300
MaxValue: 900
Description: Timeout in seconds for PreHumanLambba. Default is 300.
ConsolidationLambdaTimeoutInSeconds:
Type: Number
Default: 300
MaxValue: 900
Description: Timeout in seconds for ConsolidationLambba. Default is 300.
Resources:
SemiStructuredDocumentsS3Bucket:
Type: AWS::S3::Bucket
Properties:
BucketName:
Fn::Sub: comprehend-semi-structured-documents-${AWS::Region}-${AWS::AccountId}
VersioningConfiguration:
Status: Enabled
BucketEncryption:
ServerSideEncryptionConfiguration:
- ServerSideEncryptionByDefault:
SSEAlgorithm: AES256
CorsConfiguration:
CorsRules:
- AllowedHeaders: []
AllowedMethods: [GET]
AllowedOrigins: ['*']
SemiStructuredDocumentsS3BucketPolicy:
Type: AWS::S3::BucketPolicy
Properties:
Bucket:
Ref: SemiStructuredDocumentsS3Bucket
PolicyDocument:
Version: "2012-10-17"
Statement:
- Sid: "S3GetObjectGT"
Effect: "Allow"
Principal:
AWS:
Fn::Sub: "arn:aws:iam::${AWS::AccountId}:root"
Action:
- s3:GetObject
Resource:
Fn::Sub: "arn:aws:s3:::${SemiStructuredDocumentsS3Bucket}/*"
BucketAccessPolicy:
Type: AWS::IAM::Policy
Properties:
Roles:
- Ref: SageMakerExecutionRole
- Ref: GTPreHumanTaskLambdaExecutionRole
- Ref: GTAnnotationConsolidationLambdaExecutionRole
PolicyName: BucketAccessPolicy
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- s3:ListBucket
Resource:
- !Sub 'arn:aws:s3:::${SemiStructuredDocumentsS3Bucket}'
- Effect: "Allow"
Action:
- s3:PutObject
- s3:GetObject
Resource:
- !Sub 'arn:aws:s3:::${SemiStructuredDocumentsS3Bucket}/*'
SageMakerExecutionRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service: lambda.amazonaws.com
AWS: !GetAtt GTAnnotationConsolidationLambdaExecutionRole.Arn
Action: sts:AssumeRole
- Effect: Allow
Principal:
Service: sagemaker.amazonaws.com
Action: sts:AssumeRole
ManagedPolicyArns:
- arn:aws:iam::aws:policy/AmazonS3FullAccess
- arn:aws:iam::aws:policy/AmazonSageMakerFullAccess
Policies:
- PolicyName: LambdaInvokePolicy
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- lambda:InvokeFunction
Resource:
- !GetAtt GTPreHumanTaskLambdaFunction.Arn
- !GetAtt GTAnnotationConsolidationLambdaFunction.Arn
GTPreHumanTaskLambdaExecutionRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service: lambda.amazonaws.com
Action: sts:AssumeRole
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
- arn:aws:iam::aws:policy/AmazonSageMakerFullAccess
Policies:
- PolicyName: TextractPolicy
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- textract:AnalyzeDocument
- textract:DetectDocumentText
Resource: '*'
GTAnnotationConsolidationLambdaExecutionRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service: lambda.amazonaws.com
Action: sts:AssumeRole
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
GTPreHumanTaskLambdaFunction:
Type: AWS::Serverless::Function
Properties:
Handler: pre_human_task_lambda.lambda_handler
MemorySize: 10240
Role:
Fn::GetAtt: [GTPreHumanTaskLambdaExecutionRole, Arn]
CodeUri: src
Layers:
- !Ref PopplerBinariesLayer
Runtime: python3.8
Timeout: !Ref PreHumanLambdaTimeoutInSeconds
GTAnnotationConsolidationLambdaFunction:
Type: AWS::Serverless::Function
Properties:
Handler: annotation_consolidation_lambda.lambda_handler
MemorySize: 10240
Role: !GetAtt GTAnnotationConsolidationLambdaExecutionRole.Arn
CodeUri: src
Runtime: python3.8
Timeout: !Ref ConsolidationLambdaTimeoutInSeconds
PopplerBinariesLayer:
Type: AWS::Serverless::LayerVersion
Properties:
LayerName: PopplerBinariesLayer
Description: Poppler binaries needed to extract PDF
ContentUri: Layers/Poppler/
CompatibleRuntimes:
- python3.8
LicenseInfo: 'GPLv2'
Outputs:
GTPreHumanTaskLambdaFunctionName:
Description: Gt Pre Human Task Lambda Function Name.
Value: !GetAtt GTPreHumanTaskLambdaFunction.Arn
GTAnnotationConsolidationLambdaFunctionName:
Description: Gt Annotation Consolidation Lambda Function Name.
Value: !GetAtt GTAnnotationConsolidationLambdaFunction.Arn
SemiStructuredDocumentsS3Bucket:
Description: S3 Bucket that stores the manifests and output data for the Amazon SageMaker Ground Truth job.
Value: !Ref SemiStructuredDocumentsS3Bucket
SageMakerRoleARN:
Description: IAM Role used assumed by Amazon SageMaker to invoke pre- and post-labeling functions during the Amazon SageMaker Ground Truth Job.
Value: !GetAtt SageMakerExecutionRole.Arn
GTPreHumanTaskLambdaRoleARN:
Description: Role for GT Pre Human Task function lambda.
Value: !GetAtt GTPreHumanTaskLambdaExecutionRole.Arn
GTAnnotationConsolidationLambdaRoleARN:
Description: Role for GT Annotation Consolidation function lambda.
Value: !GetAtt GTAnnotationConsolidationLambdaExecutionRole.Arn