AWS学习笔记(二)--CLI管理Image,Instance,Snapshot,S3

1. Image

create-image

$ aws ec2 create-image --instance-id i-825465ba --name "Prod Template" --description "Prod Template" --no-reboot

执行成功后会输出ImageId.

create-tags
通过EC2 Management Console查看AMIs时,列表中的第一项是Name,执行create-image命令后,这项是空的,还需执行:

$ aws ec2 create-tags --resources ami-19af7b74 --tags "Key=Name,Value=Prod Template"

modify-image-attribute
To make an AMI public

$ aws ec2 modify-image-attribute --image-id ami-19af7b74 --launch-permission "{\"Add\": [{\"Group\":\"all\"}]}"

To make an AMI private

$ aws ec2 modify-image-attribute --image-id ami-19af7b74 --launch-permission "{\"Remove\": [{\"Group\":\"all\"}]}"

To grant launch permission to an AWS account

$ aws ec2 modify-image-attribute --image-id ami-19af7b74 --launch-permission "{\"Add\": [{\"UserId\":\"123456789012\"}]}"

To removes launch permission from an AWS account

$ aws ec2 modify-image-attribute --image-id ami-19af7b74 --launch-permission "{\"Remove\": [{\"UserId\":\"123456789012\"}]}"

deregister-image
After you deregister an AMI, it can‘t be used to launch new instances. This command does not delete the AMI.

$ aws ec2 deregister-image --image-id ami-19af7b74

Delete Image
创建image时会创建一个snapshot,要删除image,先执行deregister-image,再执行delete-snapshot即可。
查询SnapshotId:

$ aws ec2 describe-snapshots --query Snapshots[*].[SnapshotId] --filter Name=description,Values=*ami-19af7b74*

删除snapshot

$ aws ec2 delete-snapshot --snapshot-id snap-8e2718bd

describe-images
查看所有image,包含public的(会显示很多AWS public image)

$ aws ec2 describe-images

查看自己帐号创建的image

$ aws ec2 describe-images --owners self --query Images[*].[Name,ImageId]

查看private image

$ aws ec2 describe-images --query Images[*].[Name,ImageId,OwnerId] --filter "Name=is-public,Values=false"

2. Instance

run-instances
Launches the specified number of instances using an AMI for which you have permissions.

To launch an instance in EC2-Classic

$ aws ec2 run-instances --image-id ami-1a2b3c4d --count 1 --instance-type t1.micro --key-name MyKeyPair --security-groups MySecurityGroup

To launch an instance in EC2-VPC

$ aws ec2 run-instances --image-id ami-abc12345 --count 1 --instance-type t2.micro --key-name MyKeyPair --security-group-ids sg-903004f8 --subnet-id subnet-6e7f829e

注意: 必须使用--security-group-ids

start-instances

$ aws ec2 start-instances --instance-ids i-1234567890abcdef0

stop-instances

$ aws ec2 stop-instances --instance-ids i-1234567890abcdef0

reboot-instances

$ aws ec2 reboot-instances --instance-ids i-1234567890abcdef5

terminate-instances

$ aws ec2 terminate-instances --instance-ids i-1234567890abcdef0

describe-instances
To describe all instances with a Name=A000 tag

$ aws ec2 describe-instances --filters "Name=tag:Name,Values=A000"

To describe all EC2 instances that have an instance type of m1.small or m1.medium that are also in the us-west-2c Availability Zone

$ aws ec2 describe-instances --filters "Name=instance-type,Values=m1.small,m1.medium" "Name=availability-zone,Values=us-west-2c"

monitor-instances
By default, Amazon EC2 sends metric data to CloudWatch in 5-minute periods. To send metric data for your instance to CloudWatch in 1-minute periods, you can enable detailed monitoring on the instance.

To enable detailed monitoring for an existing instance

$ aws ec2 monitor-instances --instance-ids i-1234567890abcdef0

To enable detailed monitoring when launching an instance

$ aws ec2 run-instances --image-id ami-09092360 --monitoring Enabled=true...

To disable detailed monitoring

$ aws ec2 unmonitor-instances --instance-ids i-1234567890abcdef0

3. Snapshot & Volume

create-snapshot
Creates a snapshot of an EBS volume and stores it in Amazon S3. You can use snapshots for backups, to make copies of EBS volumes, and to save data before shutting down an instance.

$ aws ec2 create-snapshot --volume-id vol-1234567890abcdef0 --description "This is my root volume snapshot."

create-volum
To create a new volume

$ aws ec2 create-volume --size 80 --region us-east-1 --availability-zone us-east-1a --volume-type gp2

To create a new Provisioned IOPS (SSD) volume from a snapshot

$ aws ec2 create-volume --region us-east-1 --availability-zone us-east-1a --snapshot-id snap-066877671789bd71b --volume-type io1 --iops 1000

attach-volume
Attaches an EBS volume to a running or stopped instance and exposes it to the instance with the specified device name.

$ aws ec2 attach-volume --volume-id vol-1234567890abcdef0 --instance-id i-01474ef662b89480 --device /dev/sdf

Available Device Names

delete-volume
Deletes the specified EBS volume. The volume must be in the available state (not attached to an instance).

$ aws ec2 delete-volume --volume-id vol-049df61146c4d7901

4. S3

mb
Creates an S3 bucket.

$ aws s3 mb s3://mybucket

cp
将一个对象从S3 复制到本地

$ aws s3 cp s3://my_bucket/my_folder/my_file.ext my_copied_file.ext

将一个对象复制到S3

$ aws s3 cp my_copied_file.ext s3://my_bucket/my_folder/my_file.ext

将一个对象从S3复制到另一个S3

$ aws s3 cp s3://my_bucket/my_folder/my_file.ext s3://my_bucket/my_folder/my_file2.ext

sync
Syncs directories and S3 prefixes. Recursively copies new and updated files from the source directory to the destination.
同步本地文件到S3

$ aws s3 sync . s3://mybucket

将整个S3 存储桶下载到本地目录

$ aws s3 sync s3://remote_S3_bucket local_directory

S3间的同步

$ aws s3 sync s3://mybucket s3://mybucket2

rb
Deletes an empty S3 bucket. A bucket must be completely empty of objects and versioned objects before it can be deleted. However, the --force parameter can be used to delete the non-versioned objects in the bucket before the bucket is deleted.

$ aws s3 rb s3://mybucket --force

原文地址:http://blog.51cto.com/7308310/2071502

时间: 2024-08-27 13:52:19

AWS学习笔记(二)--CLI管理Image,Instance,Snapshot,S3的相关文章

AWS学习笔记(一)--CLI基础知识(测试)

Installing the AWS CLI Install the AWS CLI Using pip on linux1) Install python---Check to see if Python is already installed---$ python --version---Install python---$ sudo yum install python 2) Install pip---check pip---$ pip -V---install pip---$ cur

Object C学习笔记26-文件管理(二)

上一篇简单的介绍了如何获取文件属性,删除,拷贝文件等,本文继续记录Object C中文件IO操作. 一. 获取文件的执行主目录 在Object C中提供了一个方法 NSHomeDirectory() 用于获得执行执行的主目录,使用如下代码测试: NSString *homePath=NSHomeDirectory(); NSLog(@"执行文件的主目录:%@",homePath); 通过以上代码可以正确的输出应用程序的执行目录,上一张也提到了文件的目录问题,这个和Windows系统的有

Android学习笔记二十九之SwipeRefreshLayout、RecyclerView和CardView

Android学习笔记二十九之SwipeRefreshLayout.RecyclerView和CardView 前面我们介绍了AlertDialog和几个常用的Dialog,ProgressDialog进度条提示框.DatePickerDialog日期选择对话框和TimePickerDialog时间选择对话框.这一节我们介绍几个新的API控件SwipeRefreshLayout.RecyclerView和CardView,这几个API控件都是google在Android5.0推出的.下面我们来学

Object C学习笔记25-文件管理(一)

在此篇文章中简单记录一下文件管理,在Object C中NSFileManager用于管理文件已经路径.在Object C中的文件路径可以是相对路径也可以是绝对路径.斜线"/"开头,斜线实际上就是一个目录,称为 根目录.字符(-)用作用户主目录的缩写.点" . "表示当前目录,两点"  .. "表示父目录. 一. 创建NSFileManager 对象 NSFileManager非常简单,可以使用如下方式来创建NSFileManager对象. NSS

Qt学习笔记-Widget布局管理

Qt学习笔记4-Widget布局管理 以<C++ GUI Programming with Qt 4, Second Edition>为参考 实例:查找对话框 包含三个文件,finddialog.h,finddialog.cpp及main.cpp. //finddialog.h代码 #ifndef FINDDIALOG_H#define FINDDIALOG_H #include <QDialog> class QCheckBox;class QLabel;class QLineE

NFC学习笔记二——Libnfc简介与安装

一直想把自己对过的英文文章做一下翻译记录下来,趁着学习NFC,现将libnfc首页的对libnfc介绍和在不同操作系统上对libnfc安装的文章做一下翻译,一方面提高一下自己的英语,另一方面学习一下libnfc. 原文地址:http://nfc-tools.org/index.php?title=Libnfc 公共平台独立的近场通讯(NFC)库 libnfc是GNU公共许可正下发布的第一个免费的底层的NFC开发包和编程API.它对任何人事完全免费和公开的.这个列表显示了libnfc支持的功能.l

linux学习笔记二:硬盘信息查询

在linux管理中,硬盘管理是很重要的一部分.包括阵列,分区,逻辑卷等操作,在对硬盘操作前,需要充分的了解硬盘的信息.常用的硬盘查询有以下几种: 1.df  查看文件系统空间使用情况: linux-lszd-db:~ # dfFilesystem     1K-blocks     Used Available Use% Mounted on/dev/sda6      809262496 37615092 770825244   5% /udev             8076412    

Android学习笔记二十之Toast吐司、Notification通知、PopupWindow弹出窗

Android学习笔记二十之Toast吐司.Notification通知.PopupWindow弹出窗 Toast吐司 Toast吐司是我们经常用到的一个控件,Toast是AndroidOS用来显示消息的一种机制,它与Dialog不同,Toast不会获取到焦点,通常显示一段时间之后就会自动消失,下面我们来介绍Toast的几种常用方式: 第一种,默认显示方式,也是最常用的方式: Toast.makeText(MainActivity.this, "这是默认的显示方式", Toast.LE

CCNA 学习笔记(二)--CISCO设备初接触

CCNA 学习笔记(二)--初识CISCO设备 上一章我们认识到网络方面的基础知识了,现在我们正式接触CISCO设备. 1.首先我们先了解一台CISCO设备里的主要组件: ROM(只读存储器):主要保存着开机自检软件.保存路由器启动引导程序. RAM(随机存储器):断电会把数据丢失.可以存储配置文件.>>>相当于PC的内存 NVRAM(非易失存储器):断电不会丢失.用来保存用户配置文件.IP.startup-config.主机名.路由协议等等. FLASH(闪存):主要是保存完整的