はじめに
AWS Lambda(Python)を使うならやったほうが良いことをまとめてみた。
まだ試していないものも含む。随時更新。
公式
- Operating Lambda: パフォーマンスの最適化 – Part 1
- Operating Lambda: パフォーマンスの最適化 – Part 2
- Operating Lambda: パフォーマンスの最適化 – Part 3
Lambdaを理解
やったほうがよさそうなこと & 関連便利機能
Jeffyフレームワークの適用⇒LambdaではPowertoolsのほうが最適っぽいので削除
トレースやロギングの共通処理の実装を簡略化できる。AWS Lambda Powertoolsの利用
Logging、Tracing、Metrics、Utilitiesが利用できる。AWS Lambda Destinationsの適用
Lambdaの実行結果に応じて次の処理を実施することができる。AWS Lambda Layersの適用
よく使うライブラリを共通化できる。複数の CPU/GPU にかけて並列化して、エッジでの深層学習の推論を高速化する
重い処理を並列処理する。Lambdaのメモリ割り当てを自動で最適化!!AWS Lambda Power Tuning
メモリ割り当て最適化する。AWS Lambdaのコスト削減
プロファイルツールの導入する。Elastic File System
1つまたは複数の同時実行される Lambda 関数、従来から対応している EC2 と Fargate を跨ってデータ (ファイル) を永続的に保存および共有Lambda + RDS 接続にRDS Proxyを使ってみた
RDSを使うなら。VPC 外の Lambda 関数を作らせない! AWS Lambda に VPC 設定に関する IAM 条件キーが追加されました!
「特定のサブネットにのみ関連づけ可能」「特定の SecuriryGroup は指定不可」「 VPC に関連づける場合のみ Lambda 関数の作成可能」の制御が可能になった。Lambdaのランタイムにカスタムランタイム on Amazon Linux2が利用できるようになりました
カスタムランタイムの実行基盤はAmazon Linux一択だったが、今回からAmazon Linux2の上で任意のコードが実行可能になったLambdaは無いけど残り続けているCloudWatch Logsのロググループ一覧を取得する
Lambdaを削除したときlogが残りがちなので整理する用Lambdaの性能把握、比較が一瞬で! CloudWatch Lambda InsightsがGAになりました
Lambda 関数からの詳細なパフォーマンスメトリクス、ログ、メタデータの収集を開始できる
便利な小ネタ
関連
- pipの最新化(buildspec.ymlに追加)
# pipでアップデートがあるパッケージの一覧を表示
pip list -o
# コマンドで一括アップデート
pip list -o | tail -n +3 | awk '{ print $1 }' | xargs pip install -U