-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserverless.yml
150 lines (142 loc) · 4.12 KB
/
serverless.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
service: poc-pdf-textract
frameworkVersion: "2 || 3"
plugins:
- serverless-step-functions
- serverless-pseudo-parameters
provider:
name: aws
runtime: python3.8
profile: default
stage: ${opt:stage, 'dev'}
region: us-west-2
lambdaHashingVersion: 20201221
ecr:
# In this section you can define images that will be built locally and uploaded to ECR
images:
scanOnPush: true
appimage:
path: ./
iamRoleStatements:
- Effect: Allow
Action: s3:*
Resource: "*"
- Effect: Allow
Action: textract:*
Resource: "*"
- Effect: Allow
Action: sqs:*
Resource: "*"
custom:
PDF_BUCKET : ${self:service}-pdfdownload-${opt:stage,'dev'}
STATE_MACHINE_TEXT_TRACT: ${self:service}-${opt:stage,'dev'}
ROLE_STATE_MACHINE : ${self:service}-role-stepFunction-${opt:stage,'dev'}
EVENT_BUST_NAME: ${self:service}-eventBus-${opt:stage,'dev'}
functions:
StarJob:
handler: startJob.handler
GetResult:
handler: getResult.handler
Datasort:
handler: datasort.handler
stepFunctions:
stateMachines:
stepMachineTextTract:
events:
- eventBridge:
eventBusName: default
event:
source:
- aws.s3
detail-type:
- "Object Created"
detail:
bucket:
name:
- "${self:custom.PDF_BUCKET}"
object:
key:
- prefix: 'uploadpdf/'
name: "${self:custom.STATE_MACHINE_TEXT_TRACT}"
definition:
Comment: "Resolve process async of TextTract"
StartAt: Start Job
States:
Start Job:
Type: Task
Resource:
Fn::GetAtt: [StarJob, Arn]
Next: Wait
Wait:
Type: Wait
Seconds: 5
Next: Get Result
Get Result:
Type: Task
Resource:
Fn::GetAtt: [GetResult, Arn]
Next: Is Job Done
Is Job Done:
Type: Choice
Choices:
- Variable: "$.job_status"
StringEquals: "IN_PROGRESS"
Next: Wait
- Variable: "$.job_status"
StringEquals: "SUCCEEDED"
Next: Data Sort
- Variable: "$.job_status"
StringEquals: "FAILD"
Next: Final State
Default: Final State
Data Sort:
Type: Task
Resource:
Fn::GetAtt: [Datasort, Arn]
Next: Final State
Final State:
Type: Pass
End: true
resources:
Resources:
ExtractionBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: "${self:custom.PDF_BUCKET}"
NotificationConfiguration:
EventBridgeConfiguration:
EventBridgeEnabled: true
CloudTrailBucketPolicy:
DependsOn:
- ExtractionBucket
Type: "AWS::S3::BucketPolicy"
Properties:
Bucket: "${self:custom.PDF_BUCKET}"
PolicyDocument:
Version: "2012-10-17"
Statement:
-
Sid: "AWSCloudTrailAclCheck"
Effect: "Allow"
Principal:
Service: "cloudtrail.amazonaws.com"
Action: "s3:GetBucketAcl"
Resource: "arn:aws:s3:::${self:custom.PDF_BUCKET}"
-
Sid: "AWSCloudTrailWrite"
Effect: "Allow"
Principal:
Service: "cloudtrail.amazonaws.com"
Action: "s3:PutObject"
Resource: "arn:aws:s3:::${self:custom.PDF_BUCKET}/AWSLogs/*"
Condition:
StringEquals:
s3:x-amz-acl: "bucket-owner-full-control"
CloudTrail:
DependsOn:
- ExtractionBucket
- CloudTrailBucketPolicy
Type: "AWS::CloudTrail::Trail"
Properties:
S3BucketName: "${self:custom.PDF_BUCKET}"
TrailName: ${self:service}-cloudTrail-bucket
IsLogging: true