LoginSignup
3
2

More than 5 years have passed since last update.

古いruntimeのAWS Lambdaを一括削除する

Posted at

Lambdaで古いruntimeが設定されているfunctionがあるとアラートが飛んできて鬱陶しいです。

AWS Lambda to end support for Node.js v0.10 runtime, please migrate to Node.js v4.3 or v6.10 immediately

LATEST 以外のバージョンのfunctionも古いruntimeが設定されていると、アラートが飛んで来るので、古いruntimeのfunctionはすべて削除してしまいます。

aws lambda list-functions | \
    jq ".Functions[].FunctionName" -r | \
    xargs -I{} aws lambda list-versions-by-function --function-name {} | \
    jq -r '.Versions[] | select(.Runtime == "nodejs" and .Version != "$LATEST") | .FunctionArn' | \
    xargs -I{} aws lambda delete-function --function-name {}

上のコマンドを実行するだけです。念のため、バージョンが $LATEST のものは除外しています。

aws cliを実行するのが直列なので時間がかかりますが、 xargs の -P オプションを使って適当に並列化すれば良さそうです。

3
2
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
3
2