forked from yai333/ImageTextExtractExample
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate.yaml
More file actions
128 lines (118 loc) · 3.16 KB
/
Copy pathtemplate.yaml
File metadata and controls
128 lines (118 loc) · 3.16 KB
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
AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31
Globals:
Function:
Timeout: 60
Parameters:
Stage:
Type: String
Default: dev
BucketName:
Type: String
Default: aiyi.demo.textract
Resources:
TextractSNSTopic:
Type: AWS::SNS::Topic
Properties:
DisplayName: !Sub "textract-sns-topic"
TopicName: !Sub "textract-sns-topic"
Subscription:
- Protocol: lambda
Endpoint: !GetAtt TextractEndFunction.Arn
TextractSNSTopicPolicy:
Type: AWS::Lambda::Permission
Properties:
FunctionName: !Ref TextractEndFunction
Principal: sns.amazonaws.com
Action: lambda:InvokeFunction
SourceArn: !Ref TextractSNSTopic
TextractEndFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: src/
Handler: handler.textractEndHandler
Runtime: nodejs12.x
Role: !GetAtt TextractRole.Arn
Policies:
- AWSLambdaExecute
- Statement:
- Effect: Allow
Action:
- "s3:PutObject"
Resource: !Join [":", ["arn:aws:s3::", !Ref BucketName]]
TextractStartFunction:
Type: AWS::Serverless::Function
Properties:
Environment:
Variables:
TEXT_EXTRACT_ROLE: !GetAtt TextractRole.Arn
SNS_TOPIC: !Ref TextractSNSTopic
Role: !GetAtt TextractRole.Arn
CodeUri: src/
Handler: handler.textractStartHandler
Runtime: nodejs12.x
Events:
PDFUploadEvent:
Type: S3
Properties:
Bucket: !Ref S3Bucket
Events: s3:ObjectCreated:*
Filter:
S3Key:
Rules:
- Name: suffix
Value: ".pdf"
TextractRole:
Type: AWS::IAM::Role
Properties:
RoleName: "TextractRole"
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Principal:
Service:
- "textract.amazonaws.com"
- "lambda.amazonaws.com"
Action:
- "sts:AssumeRole"
ManagedPolicyArns:
- "arn:aws:iam::aws:policy/AWSLambdaExecute"
Policies:
- PolicyName: "TextractRoleAccess"
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- "sns:*"
Resource: "*"
- Effect: Allow
Action:
- "textract:*"
Resource: "*"
GetTextractResult:
Type: AWS::Serverless::Function
Properties:
Role: !GetAtt TextractRole.Arn
CodeUri: src/
Handler: handler.getTextractResult
Runtime: nodejs12.x
Events:
TextExactStart:
Type: HttpApi
Properties:
Path: /textract
Method: post
MyHttpApi:
Type: AWS::Serverless::HttpApi
Properties:
StageName: !Ref Stage
Cors:
AllowMethods: "'OPTIONS,POST,GET'"
AllowHeaders: "'Content-Type'"
AllowOrigin: "'*'"
S3Bucket:
Type: AWS::S3::Bucket
Properties:
BucketName: !Ref BucketName