📢 Webサイト閉鎖と移転のお知らせ
このWebサイトは2026年9月に閉鎖いたします。
新しい記事は移転先で追加しております。(旧サイトでは記事を追加しておりません)

141行目: 141行目:
     std::cerr << "✗ 呼び出し失敗: " << outcome.GetError().GetMessage() << std::endl;
     std::cerr << "✗ 呼び出し失敗: " << outcome.GetError().GetMessage() << std::endl;
     return false;
     return false;
}
</syntaxhighlight>
<br><br>
== Lambda関数の一覧の取得 ==
アカウント内に存在するLambda関数の一覧を取得する。<br>
関数の基本情報 (ランタイム、メモリ、タイムアウト等) も同時に取得することができる。<br>
<br>
<syntaxhighlight lang="c++">
#include <aws/lambda/LambdaClient.h>
#include <aws/lambda/model/ListFunctionsRequest.h>
// Aws::Lambda::Model::ListFunctionsRequest
// Lambda関数一覧取得リクエストを表すクラス
// オプションで最大取得数 (MaxItems) や ページネーショントークン (Marker) を設定できる
Aws::Lambda::Model::ListFunctionsRequest request;
// ListFunctions()
// アカウント内のLambda関数一覧を取得するメソッド
// 指定したリージョン内の全ての関数情報を返す
auto outcome = m_lambdaClient->ListFunctions(request);
// IsSuccess() : 呼び出しが成功したかをチェック
if (outcome.IsSuccess()) {
    // GetResult() - 成功時の結果オブジェクトを取得
    const auto& result = outcome.GetResult();
    // GetFunctions()
    // Lambda関数設定のベクトル (std::vector) を返す
    // 各要素はFunctionConfigurationオブジェクト (個々のLambda関数の設定情報)
    const auto& functions = result.GetFunctions();
    // 各関数の情報を取得
    for (const auto& func : functions) {
      // GetFunctionName()
      // Lambda関数の名前を取得
      // 例 : "my-function", "data-processor", "api-handler"
      std::string functionName = func.GetFunctionName();
      // GetHandler()
      // Lambda関数のハンドラを取得
      // ハンドラは関数のエントリーポイントを指定する
      // 例 : "index.handler" (Node.js), "lambda_function.lambda_handler" (Python)
      std::string handler = func.GetHandler();
      // GetRuntime()
      // Lambda関数のランタイム環境を列挙型で取得
      // 例 : Python3_9, nodejs18_x, java17, dotnet6, go1_x, ruby3_2
      Aws::Lambda::Model::Runtime runtime = func.GetRuntime();
      // RuntimeMapper::GetNameForRuntime()
      // Runtime列挙型を文字列表現に変換するユーティリティメソッド
      // 例 : Runtime::Python3_9 → "python3.9"
      std::string runtimeName = Aws::Lambda::Model::RuntimeMapper::GetNameForRuntime(runtime);
      // GetMemorySize()
      // Lambda関数に割り当てられたメモリサイズ (MB単位) を取得
      // 設定可能範囲 : 128[MB]~10,240[MB] (10[GB])
      // メモリサイズに比例してCPUパワーも増加する
      int memorySize = func.GetMemorySize();
      // GetTimeout()
      // Lambda関数のタイムアウト時間 (秒単位) を取得
      // 設定可能範囲: 1秒~900秒 (15分)
      // この時間を超えると関数の実行が強制終了される
      int timeout = func.GetTimeout();
      // GetLastModified()
      // 関数が最後に更新された日時をISO 8601形式で取得
      // 例 : "2024-01-15T10:30:45.123+0000"
      std::string lastModified = func.GetLastModified();
      // GetFunctionArn()
      // Lambda関数のAmazon Resource Name (ARN) を取得
      // ARNは関数を一意に識別するグローバル識別子
      // 例 : "arn:aws:lambda:us-east-1:123456789012:function:my-function"
      std::string functionArn = func.GetFunctionArn();
      // GetDescription()
      // Lambda関数の説明文を取得
      // コンソールやCLIで設定した関数の説明を返す
      std::string description = func.GetDescription();
      // その他にも取得可能な情報:
      // - GetCodeSize()    : 関数コードのサイズ (バイト単位)
      // - GetRole()        : 関数に関連付けられたIAMロールのARN
      // - GetVersion()    : 関数のバージョン番号
      // - GetLayers()      : 関数にアタッチされたレイヤーの情報
      // - GetEnvironment() : 環境変数の設定
    }
    return true;
}
else {
    // GetError() - 失敗時のエラー情報を取得
    std::cerr << "✗ 取得失敗: " << outcome.GetError().GetMessage() << std::endl;
    return false;
}
</syntaxhighlight>
<br><br>
== エラーハンドリング ==
全ての操作はOutcomeオブジェクトを返すため、必ず <code>IsSuccess</code> メソッドで確認する。<br>
<br>
<syntaxhighlight lang="c++">
auto outcome = m_lambdaClient->Invoke(request);
// 必ず成功 / 失敗を確認
if (!outcome.IsSuccess()) {
    // GetError() : エラー情報オブジェクトを取得
    auto error = outcome.GetError();
    // GetErrorType() : エラーの種類を列挙型で取得
    // 例 : INVALID_PARAMETER_VALUE, RESOURCE_NOT_FOUND, ACCESS_DENIED
    std::cerr << "エラーコード: " << error.GetErrorType() << std::endl;
    // GetMessage() : エラーの詳細メッセージを取得
    // ユーザーに表示可能な分かりやすいエラー説明
    std::cerr << "メッセージ: " << error.GetMessage() << std::endl;
    // GetExceptionName() : AWS APIが返した例外の名前を取得
    // 例 : "ResourceNotFoundException", "InvalidParameterValueException"
    std::cerr << "例外名: " << error.GetExceptionName() << std::endl;
  }
  }
  </syntaxhighlight>
  </syntaxhighlight>