{EC2}Amazon EBS スナップショットの共有

https://docs.aws.amazon.com/ja_jp/AWSEC2/latest/UserGuide/ebs-modifying-snapshot-permissions.html

Snapshots are constrained to the Region in which they were created.
デフォルトの AWS マネージドキー で暗号化されたスナップショットを共有することはできません。
共有できるのは、カスタマーマネージド型キーを使用して暗号化されたスナップショットだけです。


-- 1. コマンド等のインストール

-- 1.1 aws cli version 2 インストール

curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
aws --version


-- 2. EC2インスタンス作成

aws ec2 run-instances \
--image-id ami-0404778e217f54308 \
--instance-type t3.nano \
--key-name key1 \
--tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=instance01}]' \
--instance-market-options '{"MarketType": "spot","SpotOptions": {"SpotInstanceType": "one-time"}}'


-- 3. EBSスナップショットの作成

aws ec2 create-snapshot \
--description "snapshot01" \
--volume-id vol-11111111111111111

aws ec2 describe-snapshots --owner-ids self

 


-- 4. EBSスナップショットの共有

aws ec2 modify-snapshot-attribute \
--snapshot-id snap-11111111111111111 \
--attribute createVolumePermission \
--operation-type add \
--user-ids 888888888888

aws ec2 describe-snapshot-attribute \
--snapshot-id snap-11111111111111111 \
--attribute createVolumePermission


-- 5. EBSスナップショットの共有解除

aws ec2 modify-snapshot-attribute \
--snapshot-id snap-11111111111111111 \
--attribute createVolumePermission \
--operation-type remove \
--user-ids 888888888888

aws ec2 describe-snapshot-attribute \
--snapshot-id snap-11111111111111111 \
--attribute createVolumePermission

 

-- 6. クリーンアップ


-- EC2インスタンスの削除
aws ec2 describe-instances

aws ec2 terminate-instances --instance-ids i-11111111111111111


EBSスナップショットの削除
aws ec2 describe-snapshots --owner-ids self

aws ec2 delete-snapshot \
--snapshot-id snap-11111111111111111