📗 阿里云 cli 学习/aliyun/oss - cheatsheet
类似于 aws cli 相似的命令,针对 aliyun
官方安装<推荐>
# 使用 brew
brew install aliyun-cli
# 简单安装
~/.aliyun 配置文件
配置好的文件,可以重点看里面的
config.json文件也可以用
aliyun configure list查看设置情况
{
  "current": "frontend",
  "profiles": [
    { "name": "default" },
    { "name": "cuibin" },
    { "name": "frontend" }
  ],
  "meta_path": ""
}aliyun oss ls oss://biotech-site-predict-frontend/aric_oss_test/ --profile frontend设置某个配置为默认,或者在初始化的时候,直接用 default 也可以
# 语法
aliyun configure set --profile "your_setting_key"
# 实际
aliyun configure set --profile cuibinMacOs 安装
# 1. 下载,来这里: https://github.com/aliyun/aliyun-cli
https://www.weiyun.com/disk/folder/4efd4705ea01cae0665833803b934347
# 2. 建立目录,将aliyun的bin文件解压
mkdir -p ~/github/software/aliyun
cd $HOME/github/software/aliyun
chmod +x aliyun
# 3. 将命令放到里面
ln -s $HOME/github/software/aliyun/aliyun /usr/local/bin/aliyun
# 4. check
aliyun --version配置
以下配置的,对应的替换成你自己的
- cn-hangzhou
- AccessKeyId
- AccessKeySecret
# 配置
aliyun configure set \
  --profile akProfile \
  --mode AK \
  --region cn-hangzhou \
  --access-key-id AccessKeyId \
  --access-key-secret AccessKeySecret
# 列出
aliyun configure list常用命令
# 列出
aliyun oss ls oss:// --limited-num=10
# 我的测试命令
aliyun oss ls oss://biotech-site-predict-frontendMac 下可能出现的问题
- “aliyun” cannot be opened because the developer cannot be verified.
解决办法:直接找到 aiyun 的程序,手动点击,然后允许打开
# 参考这里: https://blog.51cto.com/u_15127598/4510317常用操作
- --force: 不需要提示,直接执行
| 功能 | 代码 | 
|---|---|
| 上传(oss) |  | 
| 同步(sync) |  | 
| 删除目录 |  | 
| 查询源站 |  | 
使用 docker
常用预设
import gitlab
import os
gl = gitlab.Gitlab()
# private token or personal token authentication (GitLab.com)
gl = gitlab.Gitlab(url="https://git.saybot.net/",
                   private_token=os.getenv('GITLAB_TOKEN'))
prj = gl.projects.get(2551)
prj.variables.create({'key': 'ALIBABACLOUD_ACCESS_KEY_ID', 'value': os.genenv('ALIBABACLOUD_ACCESS_KEY_ID'), 'protected': True})
prj.variables.create({'key': 'ALIBABACLOUD_ACCESS_KEY_SECRET', 'value': os.genenv('ALIBABACLOUD_ACCESS_KEY_SECRET'), 'protected': True})
prj.variables.create({'key': 'ALIBABACLOUD_REGION_ID', 'value': os.getenv('ALIBABACLOUD_REGION_ID'), 'protected': True})
prj.variables.create({'key': 'YARN_REGISTRY', 'value': os.getenv('ALO7_YARN_REGISTRY')})利用 homebrew 安装
自己的
homebrew源,私用
 brew install afeiship/jswork/aliyun-cliCDN相关
切换到相关的账号: teacher * | AK:***Kov | Valid | cn-beijing | en
另一个内部工具: https://aosp.alo7.com/aosp/other/itools/clearCdnCache
$ aliyun cdn RefreshObjectCaches --ObjectPath https://web-assets.alo7.com/wx-exercise-preview-h5/beta/index.html
// 返回这个结果
{
	"RefreshTaskId": "16920046725",
	"RequestId": "087866EE-9420-5746-8C3A-D261E4986ADE"
}list “/” 与没有“/”的区别
webLog on 🌱 lerna via 🐠 v20.17.0 took 5m36s
$ aliyun oss ls oss://web-alo7-com/app/awesome-ci/latest -d
oss://web-alo7-com/app/awesome-ci/latest/
Object and Directory Number is: 1
0.165551(s) elapsed
webLog on 🌱 lerna via 🐠 v20.17.0 took 4s
$ aliyun oss ls oss://web-alo7-com/app/awesome-ci/latest/ -d
oss://web-alo7-com/app/awesome-ci/latest/production-1.0.3-20250312_084130/
oss://web-alo7-com/app/awesome-ci/latest/production-1.0.4-20250312_094550/
oss://web-alo7-com/app/awesome-ci/latest/production-1.0.5-20250312_100415/
oss://web-alo7-com/app/awesome-ci/latest/production-latest/
Object and Directory Number is: 4

oss cat 直接读出内容
$ aliyun oss cat oss://web-alo7-com/app/awesome-ci/latest/production-1.0.3-20250312_084130/version.json
{
  "mode": "production",
  "version": "1.0.3",
  "githash": "unknown",
  "build_time": "2025-03-12T08:41:30.419Z"
}
0.198656(s) elapsed