使用 "ec2-modify-snapshot-attribute" 自动将快照复制到另一个帐户

Using "ec2-modify-snapshot-attribute" to automatically copy snapshots to another account

我想使用 ec2-modify-snapshot-attribute 命令自动将 new 快照复制到另一个帐户。

最好的方法是什么? shell 脚本 运行 通过 cron 作业?

您有两件事想做:

  • 将 EBS 快照复制到不同的区域
  • 使 EBS 快照可用于不同的帐户

可以通过 AWS Command-Line Interface (CLI).

调用这些操作

将 EBS 快照复制到不同的区域

使用copy-snapshot command将快照复制到不同的区域:

aws --region us-east-1 ec2 copy-snapshot --source-region us-west-2 --source-snapshot-id snap-1234abcd --description "This is my copied snapshot."

快照将与同一个 AWS 账户保持关联。

使 EBS 快照可用于不同的账户

使用 modify-snapshot-attribute command 从不同的 AWS 账户授予访问权限:

aws ec2 modify-snapshot-attribute --snapshot-id snap-1a2b3c4d --attribute createVolumePermission --operation-type add --user-ids 123456789012

正在复制新快照

您还提到复制 快照。没有用于确定 'new' 快照的预先提供的逻辑,因此您的脚本必须确定要复制的快照。复制到其他区域的快照会得到一个新的snapshot-id,因此不容易匹配正本和副本。