Skip to content

New serverless pattern - sam-dotnet-responsestreaming-bedrock-agent - #3236

Open
dougperkes wants to merge 1 commit into
aws-samples:mainfrom
dougperkes:perkesdp-feature-sam-dotnet-responsestreaming-bedrock-agent
Open

New serverless pattern - sam-dotnet-responsestreaming-bedrock-agent#3236
dougperkes wants to merge 1 commit into
aws-samples:mainfrom
dougperkes:perkesdp-feature-sam-dotnet-responsestreaming-bedrock-agent

Conversation

@dougperkes

Copy link
Copy Markdown
Contributor

Issue #, if available:

Description of changes: Lambda Response Streaming with Amazon Bedrock — Story Generator (.NET)

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@marcojahn marcojahn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @dougperkes , thank you for you PR. I've added some review comments, please review.

Action:
- bedrock:InvokeModelWithResponseStream
- bedrock:InvokeModel
Resource: "*"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Lambda execution policy grants bedrock:InvokeModel and bedrock:InvokeModelWithResponseStream on Resource: "*", allowing the function to invoke any Bedrock model in the account. The actions are already scoped, but the resource can be narrowed to the specific inference profile and its underlying foundation models. Additionally, the code calls the Converse API (ConverseAsync), which only requires bedrock:InvokeModelbedrock:InvokeModelWithResponseStream is granted but unused (it is only needed for ConverseStream).


---

## Prerequisites

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add, that the sample will incur costs in the used AWS account

/// </summary>
public class TripPlannerAgent
{
private const string ModelId = "us.anthropic.claude-sonnet-5";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

US only for the sample. Please either indicate in the README.md that the access to an US region is required or (preferred) make the model choice configuration/derived from used region.

- [.NET 10 SDK](https://dotnet.microsoft.com/download/dotnet/10.0)
- [AWS SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/install-sam-cli.html)
- AWS account with credentials configured (`aws configure`)
- **Amazon Bedrock model access** — Enable access to Claude Sonnet in the [Bedrock console](https://console.aws.amazon.com/bedrock/home#/modelaccess)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not needed since ~Nov/2025

@@ -0,0 +1,214 @@
# AWS Lambda Response Streaming with Bedrock Agent — AI Trip Planner (.NET)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# AWS Lambda Response Streaming with Bedrock Agent — AI Trip Planner (.NET)
# AWS Lambda Response Streaming with Amazon Bedrock Agents — AI Trip Planner (.NET)

@@ -0,0 +1,214 @@
# AWS Lambda Response Streaming with Bedrock Agent — AI Trip Planner (.NET)

This sample demonstrates an **AI agent** built with Amazon Bedrock (Claude Sonnet) **tool use** combined with **Lambda Response Streaming through API Gateway**. The agent uses a tool-calling loop to build a day-by-day trip itinerary, streaming each day's plan to the client as it's generated.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
This sample demonstrates an **AI agent** built with Amazon Bedrock (Claude Sonnet) **tool use** combined with **Lambda Response Streaming through API Gateway**. The agent uses a tool-calling loop to build a day-by-day trip itinerary, streaming each day's plan to the client as it's generated.
This sample demonstrates an **AI agent** built with Amazon Bedrock (Claude Sonnet) **tool use** combined with **AWS Lambda Response Streaming through Amazon API Gateway**. The agent uses a tool-calling loop to build a day-by-day trip itinerary, streaming each day's plan to the client as it's generated.

# ─────────────────────────────────────────────────────────────────────
# Lambda Function — AI trip planner agent with tool use
# ─────────────────────────────────────────────────────────────────────
TripPlannerFunction:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pattern does not define a log group with a retention policy for the Lambda function. By default the implicitly created log group retains logs indefinitely, accumulating storage cost over time.

TripPlannerLogGroup:
  Type: AWS::Logs::LogGroup
  Properties:
    LogGroupName: !Sub /aws/lambda/${TripPlannerFunction}
    RetentionInDays: 14

Type: AWS_PROXY
IntegrationHttpMethod: POST
ResponseTransferMode: STREAM
TimeoutInMillis: 120000

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The integration sets TimeoutInMillis: 120000 (120s). The default API Gateway integration timeout quota is 29 seconds; to have values above it taking any effect, require a service quota increase for Regional/private REST APIs. If the account's quota has not been raised, and the sample requires it, it will not work as intended.

(preferred): make the sample guaranteed to work with the default quota, or mention in the README.md the quote increase is needed and why

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants