1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ami削除用シェルスクリプト

Posted at
#!/bin/bash

# AMIリストファイルのパス
AMI_LIST="ami_list.txt"

# ファイルが存在するか確認
if [[ ! -f "$AMI_LIST" ]]; then
  echo "AMIリストファイル $AMI_LIST が見つかりません。"
  exit 1
fi

# AMI IDのリストを1行ずつ読み込んで削除
while IFS= read -r ami_id
do
  if [[ -n "$ami_id" ]]; then
    # AMIを削除
    echo "削除中: AMI $ami_id"
    aws ec2 deregister-image --image-id "$ami_id"
    
    # エラーチェック
    if [[ $? -eq 0 ]]; then
      echo "AMI $ami_id が削除されました。"
    else
      echo "AMI $ami_id の削除に失敗しました。"
    fi
  fi
done < "$AMI_LIST"

1
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?