- Newest
- Most votes
- Most comments
How about this for deploy strands agent to AWS Lambda:
- Prepare Your Agent Code Create a Python file (e.g. agent_handler.py) with the following structure:
from strands import Agent
from typing import Dict, Any
SYSTEM_PROMPT = """You are a helpful assistant...""" # Customize this
def handler(event: Dict[str, Any], context):
input_text = event.get("text", "")
agent = Agent(system_prompt=SYSTEM_PROMPT)
response = agent.process(input_text)
return {
"statusCode": 200,
"body": response.text
}
- Package Your Lambda Function
• Your agent_handler.py • All dependencies (including strands SDK) Use a virtual environment to bundle dependencies:
python -m venv venv
source venv/bin/activate
pip install strands
mkdir package
cd package
cp -r ../venv/lib/python*/site-packages/* .
cp ../agent_handler.py .
zip -r strands_agent_lambda.zip .
-
Upload to AWS Lambda • Go to AWS Console > Lambda • Create a new function • Choose Python 3.x as runtime • Upload your strands_agent_lambda.zip under Code > Upload from .zip • Set the handler to: agent_handler.handler
-
Configure Permissions • Attach an IAM role with basic Lambda execution permissions • If your agent uses other AWS services (e.g. Bedrock, S3), add those permissions as well
Finally test:
{
"text": "What is the weather today?"
}
Expected result: To get a structured response from your agent.
Hey,
Hope you're keeping well.
To run your Strands agent in Lambda, you’ll need to deploy it as a zipped package containing both your handler code and all required dependencies. Build this package in a local environment that matches your Lambda runtime (for example, Python 3.9), install the Strands SDK and any other libraries into a folder, include your handler file, then zip the whole directory. In the Lambda console, create a new function, choose the matching runtime, upload the zip under the Code tab, and set the handler format as filename.functionname.
Thanks and regards,
Taz
Relevant content
- asked 9 months ago
- asked 8 months ago
- asked 8 months ago
- AWS OFFICIALUpdated 5 years ago
