-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathACS::FC::ExecuteScript.yml
195 lines (193 loc) · 5.7 KB
/
ACS::FC::ExecuteScript.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
FormatVersion: OOS-2019-06-01
Description:
name-en: ACS::FC::ExecuteScript
name-zh-cn: 执行python脚本(FC)
en: Execute python script
zh-cn: 执行python脚本
Parameters:
runtime:
Type: String
Label:
en: Runtime
zh-cn: 函数的运行环境
AllowedValues:
- python3.9
- python3.10
Default: python3.10
handler:
Type: String
Label:
en: Handler
zh-cn: 函数名称
Description:
en: Python script function name(example:index.handler, index is the file name, handler is the name of the script function.)
zh-cn: python脚本函数名称(例:index.handler, index是文件名,handler是脚本函数名)
Default: index.handler
script:
Type: String
Label:
en: Python Script
zh-cn: Python脚本代码
AssociationProperty: ALIYUN::OOS::Command::CommandContent
AssociationPropertyMetadata:
CommandType: RunPythonScript
Default: |-
import json
def handler(event, context):
# 解析传入的调用参数
data = json.loads(event)
handler_name = data.get('handler_name')
print(f'My name is {handler_name}')
return handler_name
inputPayload:
Type: String
Label:
en: The parameters of function invocation
zh-cn: 函数调用参数
Description:
en: 'JSON Format: {"key": "value"} Please refer to <a href="https://www.alibabacloud.com/help/en/functioncompute/user-guide/event-handlers#section-qv4-7ev-s0q" target="_blank">document</a>'
zh-cn: 'JSON格式:{"key": "value"} 详情请<a href="https://help.aliyun.com/zh/functioncompute/user-guide/event-handlers#section-qv4-7ev-s0q" target="_blank">参考</a>'
Default: '{"handler_name": "fc_demo"}'
role:
Type: String
Label:
en: FCRamRole
zh-cn: 授予函数计算所需权限的RAM角色
AssociationProperty: ALIYUN::RAM::Service::Role
AssociationPropertyMetadata:
Service: fc.aliyuncs.com
Default: ''
Tasks:
- Name: createStack
Action: 'ACS::ExecuteAPI'
Description:
en: Creates a resource stack
zh-cn: 创建资源栈
Properties:
Service: ROS
API: CreateStack
Parameters:
StackName:
Fn::Replace:
- .: _
- OOS-{{ACS::ExecutionId}}
TimeoutInMinutes: 10
DisableRollback: false
Parameters:
- ParameterKey: ParameterKeys
ParameterValue: '{{ inputPayload }}'
- ParameterKey: Script
ParameterValue: '{{ script }}'
- ParameterKey: Role
ParameterValue: '{{ role }}'
TemplateBody: |-
ROSTemplateFormatVersion: 2015-09-01
Parameters:
ParameterKeys:
Type: String
Script:
Type: String
Role:
Type: String
Default: ''
Conditions:
Role:
Fn::Equals:
- Ref: Role
- ''
Resources:
Service:
Type: ALIYUN::FC::Service
Properties:
ServiceName:
Ref: ALIYUN::StackName
Role:
Fn::If:
- Role
- ''
- Fn::Sub:
- acs:ram::${AccountId}:role/${Role}
- AccountId: '{{ ACS::AccountId }}'
Role:
Ref: Role
Function:
Type: ALIYUN::FC::Function
DependsOn: Service
Properties:
ServiceName:
Ref: ALIYUN::StackName
FunctionName:
Ref: ALIYUN::StackName
Code:
SourceCode:
Ref: Script
Handler: "{{ handler }}"
Runtime: "{{ runtime }}"
Timeout: 300
FunctionInvoker:
Type: ALIYUN::FC::FunctionInvoker
DependsOn: Function
Properties:
ServiceName:
Ref: ALIYUN::StackName
FunctionName:
Ref: ALIYUN::StackName
Async: false
Event:
Ref: ParameterKeys
ExecuteVersion: 0
Outputs:
Result:
Value:
Fn::Replace:
- FcResult:
Fn::GetAtt:
- FunctionInvoker
- Result
- FcResult
Metadata:
ALIYUN::ROS::Interface:
TemplateTags:
- acs:integrate:oos:fc_execute_script
Outputs:
stackId:
Type: String
ValueSelector: StackId
- Name: untilStackReady
Action: 'ACS::WaitFor'
OnError: deleteStack
Description:
en: Waits for the stack status util CREATE_COMPLETE
zh-cn: 等待资源栈状态至CREATE_COMPLETE
Properties:
Service: ROS
API: GetStack
Parameters:
StackId: '{{createStack.stackId}}'
DesiredValues:
- CREATE_COMPLETE
StopRetryValues:
- CREATE_FAILED
- CHECK_FAILED
- ROLLBACK_FAILED
- ROLLBACK_COMPLETE
- CREATE_ROLLBACK_COMPLETE
PropertySelector: Status
Outputs:
result:
Type: String
ValueSelector: 'Outputs[].OutputValue'
- Name: deleteStack
Action: 'ACS::ExecuteApi'
Description:
en: Deletes the stack
zh-cn: 删除资源栈
Properties:
Service: ROS
API: DeleteStack
Parameters:
StackId: '{{createStack.stackId}}'
Outputs:
Result:
Type: String
Value: '{{ untilStackReady.result }}'