某不知名博客 某不知名博客
首页
  • 《vulcat文档》
  • Web安全

    • 《BurpSuite及官方实验室》
    • 《OSWE学习历程》
  • 云原生安全

    • 《Docker命令大全》
    • 《CKS考试学习指南》
    • 《旧-Kubernetes教程》
漏洞库
  • 《渗透工具大全》
  • 《云安全》
事件库
关于
  • 分类
  • 标签
  • 归档
GitHub (opens new window)

Carsaid

安全界的小学生
首页
  • 《vulcat文档》
  • Web安全

    • 《BurpSuite及官方实验室》
    • 《OSWE学习历程》
  • 云原生安全

    • 《Docker命令大全》
    • 《CKS考试学习指南》
    • 《旧-Kubernetes教程》
漏洞库
  • 《渗透工具大全》
  • 《云安全》
事件库
关于
  • 分类
  • 标签
  • 归档
GitHub (opens new window)
  • 工具

  • 数据库

  • 云安全

    • 云计算与云安全概念
    • AWS(亚马逊云)
    • AWS命令行界面(CLI)
      • 简介
      • 安装 awscli
      • 配置 awscli
        • 快速配置
        • 配置文件
      • awscli 命令表
        • aws configure
        • Amazon EC2
        • aws ec2 describe-instances
        • aws ec2 describe-snapshots
        • aws ec2 describe-snapshot-attribute
        • aws ec2 create-volume
        • aws ec2 attach-volume
        • Amazon S3
        • aws s3 ls
        • aws s3 md
        • aws s3 rb
        • aws s3 cp
        • aws s3 mv
        • aws s3 rm
        • aws s3 sync
    • 各大公有云厂商-元数据服务地址
    • 云上服务

  • 容器技术

  • 应急响应

  • 安全设备及平台

  • 面试

  • Top榜单

  • 知识库
  • 云安全
clincat
2023-04-15
目录

AWS命令行界面(CLI)

# AWS 命令行界面(CLI)

# 简介

aws cli 是一款适用于 AWS(亚马逊云) 的命令行管理工具。

aws cli 中文文档:https://docs.amazonaws.cn/cli/ (opens new window)

# 安装 awscli

你可以在官方文档中 找到适合你系统的安装方式:https://docs.amazonaws.cn/cli/latest/userguide/getting-started-version.html (opens new window)

此处以 64位、x86架构的Linux系统 为示例,运行以下命令安装 awscli :

  • 获取 awscli 压缩包;
  • 解压;
  • 运行安装;
  • 查看 awscli 版本,如果安装成功,会显示版本信息。
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64-2.0.30.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
aws --version
1
2
3
4

# 配置 awscli

# 快速配置

运行以下命令,可以对 awscli 进行默认配置;每当你运行 awscli 的时候,将自动使用默认的配置。

  • 默认的配置文件会保存在~/.aws/目录下。
# 进行默认配置
aws configure

# 使用默认配置, 列出该账户下的 S3 存储桶
aws s3 ls
1
2
3
4
5

如果你重复运行aws configure,将会覆盖原有的配置:

# 配置文件

你可以创建多个配置文件,在不同的文件中 保存不同的访问密钥。

  • 例如,你有a和b两个账户的访问密钥,则你可以分别创建两个配置文件:a-cred和b-cred;
  • 当 awscli 指定配置文件为a-cred时,你可以访问a账户的资源;
  • b账户同理。
# 进行指定配置
aws configure --profile <配置文件名称>

# 使用指定配置, 列出该账户下的 S3 存储桶
aws s3 ls --profile <配置文件名称>
1
2
3
4
5

# awscli 命令表

# aws configure

配置 AWS 访问密钥:

aws configure

aws configure --profile <名称>
1
2
3

参数表:

参数 作用
--profile 将访问密钥等参数 保存到一个新的配置文件中

学习更多 - 官方文档:https://docs.aws.amazon.com/zh_cn/cli/latest/userguide/cli-configure-quickstart.html (opens new window)

# Amazon EC2

参数表:

参数 作用
--filters 过滤结果,格式为:
"Name=<键>,Values=<值>"
--snapshot-id 指定快照id
--attribute 指定属性
--region 指定地区
--availability-zone 指定可用区

# aws ec2 describe-instances

列出实例

# 列出所有实例
aws ec2 describe-instances

# 列出符合条件 instance-type=t2.micro 的所有实例
aws ec2 describe-instances --filters "Name=instance-type,Values=t2.micro"
1
2
3
4
5

# aws ec2 describe-snapshots

列出快照

# 列出所有快照
aws ec2 describe-snapshots

# 列出符合条件 volume-id=vol-xxx 的所有快照
aws ec2 describe-snapshots --filters "Name=volume-id,Values=vol-xxx"
1
2
3
4
5

# aws ec2 describe-snapshot-attribute

列出快照属性

# 列出所有快照及所有属性
aws ec2 describe-snapshots-attribute

# 列出快照id为 snap-0123xxx 的快照及其属性
aws ec2 describe-snapshots-attribute --snapshot-id snap-0123xxx

# 列出所有快照的 createVolumePermission 属性
aws ec2 describe-snapshots-attribute --attribute createVolumePermission
1
2
3
4
5
6
7
8

# aws ec2 create-volume

创建卷存储

# 基于快照 snap-0123xx 创建一个卷存储
aws ec2 create-volume --snapshot-id snap-0123xx

# 指定了地区 和 可用区
aws ec2 create-volume --snapshot-id snap-0123xx --region us-west-2 --availability-zone us-west-2a
1
2
3
4
5

# aws ec2 attach-volume

挂载卷存储

# 格式
aws ec2 attach-volume --volume-id <卷id> --instance-id <实例id> --device <挂载路径>

# 将卷 vol-123 挂载到实例 i-abc 的目录 /dev/sdf 下
aws ec2 attach-volume --volume-id vol-123 --instance-id i-abc --device /dev/sdf
1
2
3
4
5

# Amazon S3

awscli 提供 S3存储桶 的相关操作。

aws s3 <子命令>

# 获取帮助信息
aws s3 help
1
2
3
4
  • 存储桶 – 顶级 Amazon S3 文件夹。
  • 前缀 – 存储桶中的 Amazon S3 文件夹。
  • 对象 – 托管在 Amazon S3 存储桶中的任何项。

参数表:

参数 作用
--profile 指定配置文件
--acl 为复制到存储桶的文件 设置访问权限,支持的值:
private
public-read
public-read-write
--exclude 排除指定的文件,不对其进行操作
支持通配符 星号、问号(*、?)等
--recursive 递归,针对所指定目录下的所有文件 执行该命令
--region 指定地区,例如 us-west-2(美西2区)
...... ......

学习更多 - 官方文档:https://docs.aws.amazon.com/zh_cn/cli/latest/userguide/cli-services-s3.html (opens new window)

# aws s3 ls

列出存储桶和对象

# 列出一个账户下的所有S3存储桶
aws s3 ls

# 列出一个存储桶中的所有前缀和对象
aws s3 ls s3://<存储桶名称>

# 列出一个前缀中的所有对象
aws s3 ls s3://<存储桶名称>/<前缀名称>
1
2
3
4
5
6
7
8

# aws s3 md

创建存储桶

# 创建一个S3存储桶
aws s3 md s3://<存储桶名称>
1
2

# aws s3 rb

删除存储桶

# 删除一个 空的 S3存储桶,存储桶必须为空,否则操作不成功
aws s3 rb s3://<存储桶名称>

# 强制删除一个S3存储桶
aws s3 rb s3://<存储桶名称> --force
1
2
3
4
5

# aws s3 cp

复制对象

存储桶 与 存储桶之间的复制:

# 将bucket-a中的对象example 复制到 bucket-x当中
aws s3 cp s3://bucket-a/example s3://bucket-x/
1
2

本地 与 存储桶之间的复制:

# 将本地文件filename.txt 复制到 存储桶bucket-name
aws s3 cp filename.txt s3://bucket-name

# 将存储桶bucket-name中的文件filename.txt 复制到 本地的当前目录下
aws s3 cp s3://bucket-name/filename.txt ./
1
2
3
4
5

流式传输:

# 将文本"hello world" 流式传输 到存储桶bucket-name的filename.txt文件当中
echo "hello world" | aws s3 cp - s3://bucket-name/filename.txt

# 将filename.txt的文件内容 流式传输 到stdout(标准输出)
aws s3 cp s3://bucket-name/filename.txt -
1
2
3
4
5

实战示例:

  • 将s3://bucket-name/pre的文件内容传输到本地stdout;
  • 使用bzip2命令进行压缩;
  • 将压缩后的文件内容,上传到s3://bucket-name/key.bz2。
aws s3 cp s3://bucket-name/pre - | bzip2 --best | aws s3 cp - s3://bucket-name/key.bz2
1

# aws s3 mv

移动对象

存储桶 与 存储桶之间的移动:

# 将bucket-a中的对象example 移动到 bucket-x
aws s3 mv s3://bucket-a/example s3://bucket-x/
1
2

本地 与 存储桶之间的移动:

# 将本地文件filename.txt 移动到 存储桶bucket-name
aws s3 mv filename.txt s3://bucket-name

# 将存储桶bucket-name中的文件filename.txt 移动到 本地的当前目录下
aws s3 mv s3://bucket-name/filename.txt ./
1
2
3
4
5

# aws s3 rm

删除对象

# 从example中 删除对象 filename.txt
aws s3 rm s3://bucket-name/example/filename.txt

# 删除example下的所有对象
aws s3 rm s3://bucket-name/example --recursive
1
2
3
4
5

# aws s3 sync

同步对象

...... (opens new window)

编辑 (opens new window)
AWS(亚马逊云)
各大公有云厂商-元数据服务地址

← AWS(亚马逊云) 各大公有云厂商-元数据服务地址→

最近更新
01
API测试笔记
04-30
02
msfvenom
03-29
03
Metasploit
03-29
更多文章>
Theme by Vdoing | Copyright © 2023-2024 Carsaid | MIT License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式