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

Lambda 関数 URL を使用して Bedrock のレスポンスをストリーミングしてみた

Posted at

はじめに

今回は Bedrock のレスポンスをストリーミング対応させていきます.

構成やコードの複雑化を避けるとともに, コストをかけずにサクッと実現できないか?
ということで Lambda 関数 URL を使用してレスポンスストリーミングを実現できるか試していきます.

構成

ユーザ --- curl ---> Lambda(関数URL) ---InvokeModelWithResponseStream ---> Bedrock

AWS リソースの作成

$ git clone https://github.com/dev-kawano-y/study-aws-bedrock-with-lambda-function-urls.git
$ cd study-aws-bedrock-with-lambda-function-urls/infrastructures
$ npm ci
AWS リソースの作成
$ cdk deploy --profile ...
...
Outputs:
InfrastructuresStack.FunctionName = InfrastructuresStack-ResponseStreamingFunction...
InfrastructuresStack.FunctionUrl = https://<id>.lambda-url.<region>.on.aws/

確認

curl コマンドで確認します.
リクエスト先は上記の InfrastructuresStack.FunctionUrl を指定してください.

$ curl -X POST \
  -H "Content-Type: application/json" \
  -d '{"prompt": "こんにちは!"}' \
  --no-buffer \
  https://<id>.lambda-url.<region>.on.aws/
こんにちは!お手伝いできることがあれば、お気軽にお尋ねください。何かご質問やお話したいことはありますか?

テキストだとわからなくて申し訳ありませんが,
手元ではストリーミングできていることを確認しました.

最後に

小規模でシンプルな API で構わない場合の引き出しとしていいかもしれません.
API Gateway を使っていないのでそこは注意点です.
例えば Lambda オーソライザーは使用できないので,
FunctionUrlAuthType.NONE の場合の認証ロジックは Lambda 関数 URL 内に実装してくださいませ.

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