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?

Difyで超シンプルにAWS Lambdaを呼び出す方法(関数URL編)

Posted at

はじめに

Difyから関数URLを使ってLambdaを呼び出すシンプルな方法についての記事になります。

image.png

1. Lambda関数URLの作成

  • AWSマネジメントコンソールで対象のLambda関数を開く
  • 認証タイプ:「NONE」を選び、その他はデフォルトのままで作成します
    ※ セキュリティが他必要であれば、CORSの設定など適宜行なって下さい

image.png

Lambda関数のコード例(Python)

# Difyから送られたJSONを受け取り、レスポンスを返すシンプルな例:

import json

def lambda_handler(event, context):
    message = event.get("message", "no message")
    return {
        "statusCode": 200,
        "body": json.dumps({
            "echo": message
        })
    }

発行された関数URLをコピーします。

https://xxxxxxxxxxxxxxx.lambda-url.ap-northeast-1.on.aws/

2.Difyのワークフロー設定

下記の画像のように「HTTPリクエスト」ノードを追加します。

設定例

API: POST
URL部分: Lambda関数URLを貼り付け
ヘッダー: Content-Type: application/json
ボディ: JSON形式にしてますが、rawなど適宜変更する

image.png

まとめ

Lambda関数URLを使えば、Difyから超シンプルに呼び出せます
認証なしURLは便利ですが本番環境ではセキュリティ設計が重要なので
API GatewayやIAM認証と組み合わせましょう!

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?