Linux 共享 EC2 快照的命令行

Linux commandline to share an EC2 snapshot

我想在 Amazon AWS 上按如下方式设置批处理:

  1. 拍摄标记为 "must_backup"
  2. 的卷的快照
  3. 与帐户 B 共享这些快照
  4. 在帐户 B 中复制这些快照

这样做的目的是为了在第一个 Amazon AWS 帐户遭到破坏时保护备份。

我知道如何自动执行第 1 步和第 3 步,但是我找不到关于如何执行第 2 步的命令行示例。 官方文档https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-modifying-snapshot-permissions.html 没有提供任何示例,也没有明确说明如何在命令行上指定目标帐户。

aws cli 的示例命令:复制 ec2 快照

aws ec2 modify-snapshot-attribute --snapshot-id snap-1234567890 --user-ids other-amazon-account-id

我已经仔细检查了之前的解决方案,但还是不行。基本上 "sharing" 快照意味着允许其他帐户从该快照创建卷。

这意味着向 "createVolumePermission" 属性添加一个值

aws ec2 modify-snapshot-attribute --snapshot-id snap-<id> --user-ids <user-id-without-hypens> --attribute createVolumePermission --operation add

该操作可能需要一些时间(几分钟?),之后您就可以通过这种方式查询属性:

aws ec2 describe-snapshot-attribute --snapshot-id snap-<id> --attribute createVolumePermission

PS:对于问题中提到的目的,这可能还不够,因为 'destination' 帐户将无法看到源帐户中的任何标签,因此它将是如果源帐户共享多个相同大小的快照,则无法执行正确的备份