-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtemplate.yml
193 lines (193 loc) · 4.55 KB
/
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
ROSTemplateFormatVersion: '2015-09-01'
Transform: 'Aliyun::Serverless-2018-04-03'
Parameters:
DBInstanceName:
Type: String
Default: todo-list-db
LogProjectName:
Type: String
Default: todo-list-log
RoleNamePrefix:
Type: String
Default: todo-list
AppId:
Type: String
Resources:
dbInstance:
Type: 'ALIYUN::OTS::Instance'
Properties:
InstanceName:
Ref: DBInstanceName
todoListTable:
Type: 'ALIYUN::OTS::Table'
DependsOn: dbInstance
Properties:
TableName: 'todo_list'
InstanceName:
Ref: DBInstanceName
PrimaryKey:
- Name: uid
Type: STRING
- Name: id
Type: STRING
sessionTable:
Type: 'ALIYUN::OTS::Table'
DependsOn: dbInstance
Properties:
TableName: 'session'
InstanceName:
Ref: DBInstanceName
PrimaryKey:
- Name: id
Type: STRING
logProject:
Type: 'ALIYUN::SLS::Project'
Properties:
Name:
Ref: LogProjectName
logStore:
Type: 'ALIYUN::SLS::Logstore'
DependsOn: logProject
Properties:
ProjectName:
Ref: LogProjectName
LogstoreName: 'func-logs'
logIndex:
Type: 'ALIYUN::SLS::Index'
DependsOn: logStore
Properties:
ProjectName:
Ref: LogProjectName
LogstoreName: 'func-logs'
FullTextIndex:
Enable: 'true'
serviceRole:
Type: 'ALIYUN::RAM::Role'
Properties:
RoleName:
'Fn::Sub': '${RoleNamePrefix}-service-role'
AssumeRolePolicyDocument:
Version: 1
Statement:
- Action: 'sts:AssumeRole'
Effect: Allow
Principal:
Service:
- fc.aliyuncs.com
invokeRole:
Type: 'ALIYUN::RAM::Role'
Properties:
RoleName:
'Fn::Sub': '${RoleNamePrefix}-invoke-role'
AssumeRolePolicyDocument:
Version: 1
Statement:
- Action: 'sts:AssumeRole'
Effect: Allow
Principal:
RAM:
- 'Fn::Sub': 'acs:ram::${ALIYUN::TenantId}:root'
attachPolicy1:
Type: 'ALIYUN::RAM::AttachPolicyToRole'
DependsOn: serviceRole
Properties:
RoleName:
'Fn::Sub': '${RoleNamePrefix}-service-role'
PolicyName: AliyunOTSFullAccess
PolicyType: System
attachPolicy2:
Type: 'ALIYUN::RAM::AttachPolicyToRole'
DependsOn: serviceRole
Properties:
RoleName:
'Fn::Sub': '${RoleNamePrefix}-service-role'
PolicyName: AliyunLogFullAccess
PolicyType: System
attachPolicy3:
Type: 'ALIYUN::RAM::AttachPolicyToRole'
DependsOn: serviceRole
Properties:
RoleName:
'Fn::Sub': '${RoleNamePrefix}-service-role'
PolicyName: AliyunSTSAssumeRoleAccess
PolicyType: System
attachPolicy4:
Type: 'ALIYUN::RAM::AttachPolicyToRole'
DependsOn: invokeRole
Properties:
RoleName:
'Fn::Sub': '${RoleNamePrefix}-invoke-role'
PolicyName: AliyunFCInvocationAccess
PolicyType: System
todo-list-svc:
Type: 'Aliyun::Serverless::Service'
DependsOn:
- dbInstance
- logIndex
- invokeRole
Properties:
Role:
'Fn::GetAtt':
- serviceRole
- Arn
InternetAccess: true
db:
Type: 'Aliyun::Serverless::Function'
Properties:
Handler: index.handler
Runtime: nodejs10
Timeout: 10
MemorySize: 512
CodeUri: ./db
EnvironmentVariables:
instanceName:
Ref: DBInstanceName
tableName: 'todo_list'
sessionTableName: 'session'
session:
Type: 'Aliyun::Serverless::Function'
Properties:
Handler: index.handler
Runtime: nodejs10
Timeout: 10
MemorySize: 512
CodeUri: ./session
EnvironmentVariables:
instanceName:
Ref: DBInstanceName
sessionTableName: 'session'
stsRoleArn:
'Fn::GetAtt':
- invokeRole
- Arn
appId:
Ref: AppId
Events:
httpTrigger:
Type: HTTP
Properties:
AuthType: ANONYMOUS
Methods:
- POST
Outputs:
AccountId:
Value:
Ref: ALIYUN::TenantId
Region:
Value:
Ref: ALIYUN::Region
ServiceName:
Value:
'Fn::GetAtt':
- todo-list-svc
- ServiceName
SessionFunctionName:
Value:
'Fn::GetAtt':
- todo-list-svcsession
- FunctionName
DBFunctionName:
Value:
'Fn::GetAtt':
- todo-list-svcdb
- FunctionName