-
Notifications
You must be signed in to change notification settings - Fork 17
/
ACS::FC::ExecuteScript.yml
181 lines (177 loc) · 5.04 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
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
inputPayload:
Type: Json
Label:
en: InputPayload
zh-cn: 输入参数
Description:
en: The parameter value of the script
zh-cn: 脚本的参数值
Default: ''
script:
Type: String
Label:
en: Python Script
zh-cn: python脚本代码
AssociationProperty: ALIYUN::OOS::Command::CommandContent
AssociationPropertyMetadata:
CommandType: RunPythonScript
Default: |-
import datetime
import os
import sys
def _now(format="%Y-%m-%d %H:%M:%S"):
return datetime.datetime.now().strftime(format)
def job_start():
return ("[%s][%s] job_start" % (_now(), os.getpid()))
def handler(event, context):
return job_start()
role:
Type: String
Label:
en: RamRoleArn
zh-cn: 授予函数计算所需权限的RAM角色ARN
Description:
en: Format:"acs:ram::{{ACS::AccountId}}:role/{RoleName}, for example:"acs:ram::{{ACS::AccountId}}:role/fc-test-role"
zh-cn: 格式:"acs:ram::{{ACS::AccountId}}:role/{RoleName}, 如:"acs:ram::{{ACS::AccountId}}:role/fc-test-role"
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 }}'
TemplateBody: |-
ROSTemplateFormatVersion: 2015-09-01
Parameters:
ParameterKeys:
Type: String
Script:
Type: String
Resources:
Service:
Type: ALIYUN::FC::Service
Properties:
ServiceName:
Ref: ALIYUN::StackName
Role: "{{ 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 }}'