はじめに
Node.js 8.10 is EOL, please migrate your functions to a newer runtime version
ということらしい。
Node.js 8って全リージョン合わせてどのくらい使ってたっけ? というときに確認方法のメモを残しておく。
結論
事前準備できてる状態で、次の内容のシェルスクリプトを実行する。
# !/bin/bash
region_list=$(aws ec2 describe-regions|jq -r '.[][].RegionName'|sort)
runtime_list=$(for x in $region_list; do aws --region $x lambda list-functions| jq -cr '.[][]|.Runtime'; done)
key_list=$(echo "$runtime_list" | sort -u)
total=$(echo "$runtime_list"|wc -l)
for x in $key_list; do c=$(echo "$runtime_list" | grep $x | wc -l); p=$(echo "scale=2; 100 * $c / $total"|bc -l); echo "$x: $c ($p%)"; done
事前準備
ソフトウェア
AWS CLIとjqの準備が必要だ。
他にも使ってるが、LinuxやMacなら最初からあるだろう。
権限
対象ユーザーでは次の権限が必要になる。
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "EC2DescribeRegions",
"Effect": "Allow",
"Action": "ec2:DescribeRegions",
"Resource": "*"
},
{
"Sid": "LambdaListFunctions",
"Effect": "Allow",
"Action": "lambda:ListFunctions",
"Resource": "*"
}
]
}
順を追って実行する
リージョン一覧を取得する
まずは、 aws ec2 describe-regions
でリージョン一覧を取得する。
そして、jqでリージョン名だけの一覧に加工しておく。
region_list=$(aws ec2 describe-regions|jq -r '.[][].RegionName'|sort)
echo "$region_list"
# 例えば、こんな結果が得られる。
# ap-northeast-1
# ap-northeast-2
# ap-south-1
# ap-southeast-1
# ap-southeast-2
# ca-central-1
# eu-central-1
# eu-north-1
# eu-west-1
# eu-west-2
# eu-west-3
# sa-east-1
# us-east-1
# us-east-2
# us-west-1
# us-west-2
関数一覧
次に、 aws --region region-name lambda list-functions
で各リージョンの関数一覧を取得する。
そして、jqでランタイム名だけの一覧に加工しておく。
runtime_list=$(for x in $region_list; do aws --region $x lambda list-functions| jq -cr '.[][]|.Runtime'; done)
echo "$runtime_list"
# 例えば、こんな結果が得られる。
# nodejs8.10
# python3.6
# nodejs8.10
# python3.7
# nodejs8.10
# python3.7
# nodejs8.10
# provided
# nodejs8.10
# nodejs8.10
# nodejs8.10
# nodejs8.10
# nodejs8.10
# provided
# python3.6
# python3.6
# nodejs10.x
# python3.6
ランタイム名のユニークをとる
次に、ランタイム名だけの一覧からユニークをとる。
key_list=$(echo "$runtime_list" | sort -u)
echo "$key_list"
# 例えば、こんな結果が得られる。
# nodejs10.x
# nodejs8.10
# provided
# python3.6
# python3.7
数える
最後に、それぞれのランタイムを使ってる関数を数える。
total=$(echo "$runtime_list"|wc -l)
echo $total
for x in $key_list; do c=$(echo "$runtime_list" | grep $x | wc -l); p=$(echo "scale=2; 100 * $c / $total"|bc -l); echo "$x: $c ($p%)"; done
# 例えば、こんな結果が得られる。
# nodejs10.x: 1 (5.55%)
# nodejs8.10: 9 (50.00%)
# provided: 2 (11.11%)
# python3.6: 4 (22.22%)
# python3.7: 2 (11.11%)