You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To deploy the above agent to Lambda using the TypeScript CDK, prepare your code for deployment by creating the Lambda definition and an associated Lambda layer ([`AgentLambdaStack.ts`][AgentLambdaStack]):
66
+
To deploy the above agent to Lambda using the TypeScript CDK, prepare your code for deployment by creating the Lambda definition. You can use the official Strands Agents Lambda layer for quick setup, or create a custom layer if you need additional dependencies.
67
+
68
+
### Using the Strands Agents Lambda Layer
69
+
70
+
The fastest way to get started is to use the official Lambda layer, which includes the base `strands-agents` package:
If you need packages beyond the base `strands-agents` SDK (such as `strands-agents-tools`), create a custom layer ([`AgentLambdaStack.ts`][AgentLambdaStack]):
When using [Model Context Protocol (MCP)](../concepts/tools/mcp-tools.md) tools with Lambda, there are important considerations for connection lifecycle management.
215
+
216
+
### MCP Connection Lifecycle
217
+
218
+
**Establish a new MCP connection for each Lambda invocation.** Creating the `MCPClient` object itself is inexpensive - the costly operation is establishing the actual connection to the server. Use context managers to ensure connections are properly opened and closed:
219
+
220
+
```python
221
+
from mcp.client.streamable_http import streamablehttp_client
MCP connections are typically stateful to a particular conversation. Reusing a connection across invocations can lead to state leakage between different users or conversations. **Start with the context manager approach** and only optimize to connection reuse if needed, with careful consideration of your tenancy model.
263
+
180
264
## Summary
181
265
182
266
The above steps covered:
183
267
184
268
- Creating a Python handler that Lambda invokes to trigger an agent
185
-
-Creating the CDK infrastructure to deploy to Lambda
186
-
- Packaging up the Lambda handler and dependencies
269
+
-Infrastructure options: official Lambda layer or custom dependencies layer
270
+
- Packaging up the Lambda handler and dependencies
187
271
- Deploying the agent and infrastructure to an AWS account
272
+
- Using MCP tools with HTTP-based transports on Lambda
0 commit comments