LoginSignup
0
0

More than 3 years have passed since last update.

[AWS] aws cliで、EC2スナップショットを一括で削除する

Posted at

EC2ヘッダ画像.png

aws cliを利用して、EC2のスナップショットを一括で削除する方法を紹介します。

aws cliのバージョン

% aws --version
aws-cli/2.1.28 Python/3.8.8 Darwin/20.3.0 exe/x86_64 prompt/off

リージョンとプロファイルの設定

% export AWS_DEFAULT_REGION=ap-northeast-1
% export AWS_PROFILE=xxxxx

スナップショットを一括で削除する

describe-snapshots でスナップショットのリストを取得し、xargsコマンドでdelete-snapshotの引数として設定します。

aws ec2 describe-snapshots \
--query "Snapshots[*].[SnapshotId]" \
--owner-ids self \
--output text \
--no-cli-pager | \
xargs -I{} aws ec2 delete-snapshot \
--snapshot-id {}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0