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

AWS Lambda Durable Functions使ってみた

0
Posted at

イントロダクション

-AWS re:Invent 2025 で発表された AWS Lambda の Durable Functions により、Lambda 関数でステートが管理可能になりました。Durable Functions はリリース当初 Ohio リージョンのみ(2025/12/3)で利用可能でしたが、今回東京を含む14リージョンで新たに利用できるようになりました。(2025/12/18)

Durable Functions を使うと

  • ステップごとに進み具合を保存できる(steps)
  • 途中で一時停止できる(wait)
  • エラーが起きても自動で復旧できる
  • 待っている間はお金がかからない(課金なし)

検証

①マネジメントコンソールからDurable Functions の有効化を確認する
作成時に Lambda の Option として Durable を有効化します。
image.png

※マネジメントコンソール画面に入ると以下の2点が追加されています。
(1)Durable executions のタブが増えている

(2)デフォルト関数内に@aws/durable-execution-sdk-jsがあること
image.png

以下の関数を実行する(デフォルトで表示されるコードと同じです。)


import { withDurableExecution } from "@aws/durable-execution-sdk-js";

export const handler = withDurableExecution(async (event, context) => {
  // TODO implement

  await context.step("Step #1", (stepCtx) => {
    stepCtx.logger.info("Hello from step #1");
  });

  // Pause for 1 second without consuming CPU cycles or incurring usage charges
  await context.wait({ seconds: 1 });

  // Context logger is replay aware and will not log the same message multiple times
  context.logger.info("Waited for 1 second");

  const message = await context.step("Step #2", async () => {
    return "Hello from Durable Lambda!";
  });

  const response = {
    statusCode: 200,
    body: JSON.stringify(message),
  };
  return response;
});

image.png
image.png

以下のテストイベントにて関数を実行します。
image.png

AWS re:Inventの記事とおり、マネジメントコンソールから東京リージョンでDurable functions が利用できることが確認できました。

image.png

まとめ

AWS Lambda Durable Functionsと同様にステート管理が可能なサービスである AWS Step Functions は、ステートの高度なGUIで確認できるなど高機能ですが、フロー変更時のメンテナンスが大変だったり、複雑な処理や認証が必要な処理ではLambdaでコード を挟む必要があったりする必要がありましたが、Durable Functions の登場により、従来の実行時間が最大 15 分から最長1年間可能になったことから、Lambda だけで手軽にステート管理を実装できるようになりました。今後のステート管理サービスの動向に注目されます。

参考文献

Lambda durable functions が発表されました!
https://zenn.dev/aws_japan/articles/lambda-durable-functions

AWS Lambda Durable Functions が東京リージョンでも利用可能になりました
https://dev.classmethod.jp/articles/aws-lambda-durable-functions-tokyo-region/

AWS Lambda durable functions are now available in 14 additional AWS Regions
https://aws.amazon.com/jp/about-aws/whats-new/2025/12/lambda-durable-functions-14-additional-regions/

15分の壁崩壊!AWS Lambda Durable Functionsで「待機中ゼロ円」のAI・多段処理を実現

AWS Lambda Durable Functions が東京リージョンでも利用可能になりました | DevelopersIO
https://dev.classmethod.jp/articles/aws-lambda-durable-functions-tokyo-region/

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