删除云沙箱资源
remove 命令是对已经部署的云沙箱资源进行移除的操作,能删除的资源有:
apiKeys、volumes、team
⚠️ 注意:资源一旦移除可能无法恢复,所以在使用移除功能时,请您慎重操作。删除 volume 会丢失挂载关系,删除前确认没有沙箱正在使用它。
命令解析
当执行命令remove -h/remove --help时,可以获取帮助文档。
参数解析
| 参数全称 | 参数缩写 | Yaml 模式下必填 | 参数含义 |
|---|---|---|---|
| team | - | 选填 | 只删除 Team 自身 |
| volume | - | 选填 | 只删除存储卷;可跟名称限定范围,多个名称用 "," 分割;不跟值表示删除 s.yaml 中全部 volume |
| api-key | - | 选填 | 只删除访问密钥;可跟名称限定范围,多个名称用 "," 分割;不跟值表示删除 s.yaml 中全部 apiKey |
| assume-yes | y | 选填 | 在交互时,默认选择y |
当前命令还支持部分全局参数(例如
-a/--access,--debug等),详情可参考 Serverless Devs 全局参数文档
--team / --volume / --api-key 都不指定时,三类资源全部纳入本次删除;指定了其中任意一个,就只删除被指定的种类。
操作案例
有资源描述文件(Yaml)时,可以直接执行s remove进行资源删除。默认会对每个资源逐个确认:
? Are you sure you want to delete the api key ci (k-1039xxxxxxxx)? yes
ApiKey ci removed
? Are you sure you want to delete the volume data (v-9fquxxxxxxxx)? yes
Volume data removed
? Are you sure you want to delete the team dev (t-5lycxxxxxxxx)? yes
Team dev removed
返回结果示例:
sandbox:
region: cn-hangzhou
teamName: dev
teamID: t-5lycxxxxxxxx
removedApiKeys:
- ci
removedVolumes:
- data
removedTeam: true
按种类删除:
s remove -y # 无交互删除 s.yaml 中声明的全部资源
s remove --volume data -y # 只删除名为 data 的 volume
s remove --api-key ci,readonly -y
s remove --team -y # 只删除 Team 自身
删除资源顺序(与 deploy 严格相反):
- apiKeys
- volumes
- team
⚠️ 必须按这个顺序 —— Team 上还挂着 volume / apiKey 时删除会失败。
注意事项
-
只删除 s.yaml 中声明的资源。同一个 Team 下未声明的 volume / apiKey 会被保留,要删除请走 CLI 子命令。
-
--volume/--api-key只能指定 s.yaml 中声明过的名字,否则报错(会带上具体是哪一类):Not found in s.yaml volumes: ghost -
线上已不存在的资源会被跳过,不报错。Team 本身不存在时只 warn:
Team "dev" not found in region cn-hangzhou, nothing to remove -
如果使用了参数
-y/--assume-yes,那么就会无交互式地删除 s.yaml 中声明的所有资源,请谨慎使用此参数。 -
未确认的资源会被跳过而不是中断整个流程:
Skip removing volume data (v-9fquxxxxxxxx) -
配额(Quota)不属于某个 Team,
remove不会删除它,用quota remove单独处理。
不依赖 s.yaml 的完整清理
s cli fc-sandbox apikey list --team-name dev --table --region cn-hangzhou -a default
s cli fc-sandbox apikey remove --team-name dev --api-key-name <name> --region cn-hangzhou -a default -y
s cli fc-sandbox volume list --team-name dev --table --region cn-hangzhou -a default
s cli fc-sandbox volume remove --team-name dev --volume-name <name> --region cn-hangzhou -a default -y
s cli fc-sandbox team remove --team-name dev --region cn-hangzhou -a default -y
权限与策略说明
AliyunFCFullAccess,或按需收敛为删除权限:
{
"Version": "1",
"Statement": [
{
"Action": "fc:Delete*",
"Effect": "Allow",
"Resource": "*"
}
]
}