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
# Amazon S3 to AWS Lambda to Amazon Bedrock AgentCore
2
+
This pattern creates an AWS Lambda function to invoke an agent in AgentCore Runtime when an object is uploaded to the Amazon S3 bucket.
3
+
4
+
This Terraform template creates 2 S3 buckets (input and output), an AWS Lambda Function, and an agent in AgentCore Runtime.
5
+
6
+
Learn more about this pattern at Serverless Land Patterns: https://serverlessland.com/patterns/s3-lambda-agentcore
7
+
8
+
Important: this application uses various AWS services and there are costs associated with these services after the Free Tier usage - please see the AWS Pricing page for details. You are responsible for any AWS costs incurred. No warranty is implied in this example.
9
+
10
+
## Requirements
11
+
12
+
*[Create an AWS account](https://portal.aws.amazon.com/gp/aws/developer/registration/index.html) if you do not already have one and log in. The IAM user that you use must have sufficient permissions to make necessary AWS service calls and manage AWS resources.
13
+
*[AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html) installed and configured
3. From the command line, initialize terraform to download and install the providers defined in the configuration:
29
+
30
+
`terraform init`
31
+
32
+
4. From the command line, apply the configuration in the deploy.tf file:
33
+
34
+
`terraform apply`
35
+
36
+
1. When prompted, enter `yes` to confirm the deployment
37
+
38
+
2. Note the outputs from the deployment process, these contain the resource names and/or ARNs which are used for testing.
39
+
40
+
## How it works
41
+
42
+
S3 will invoke the Lambda function when an object is created or updated. It will pass metadata about the new object in the event argument of the Lambda invocation.
43
+
44
+
The lambda function will invoke the agent and pass a uri for the s3 file.
45
+
46
+
The agent will categorize the file as architecture, runbook, or other and identify some metadata. Then it will send the results back to the Lambda function as JSON.
47
+
48
+
The Lambda function will write the metadata to the S3 output bucket.
49
+
50
+
## Testing
51
+
52
+
Ensure you're in the correct directory (`cd serverless-patterns/s3-lambda-agentcore`). Then run the following script to test with files in the `./test-files` folder.
filename: str=Field(description="The name of the file")
14
+
system: str=Field(description="The system or service the file relates to")
15
+
keywords: List[str] =Field(description="List of relevant keywords or subjects")
16
+
17
+
classFileClassification(BaseModel):
18
+
category: Literal["architecture", "operations", "other"] =Field(description="The category of the file")
19
+
metadata: FileMetadata=Field(description="Metadata about the file")
20
+
reasoning: str=Field(description="The reasoning behind the categorization")
21
+
time: str=Field(description="The UTC timestamp of the categorization")
22
+
23
+
model_id="us.amazon.nova-pro-v1:0"
24
+
model=BedrockModel(
25
+
model_id=model_id,
26
+
)
27
+
28
+
agent=Agent(
29
+
model=model,
30
+
tools=[use_aws, current_time],
31
+
system_prompt="""
32
+
You are an IT documentation classifier. Your task is to categorize documentation files into one of three categories and extract relevant metadata.
33
+
34
+
CATEGORIES:
35
+
36
+
1. **architecture** - System design and technical architecture documentation including:
37
+
- System architecture diagrams and design documents
38
+
- Reference architectures
39
+
- API specifications and interface definitions
40
+
- Data models, database schemas, and ER diagrams
41
+
- Technology stack decisions and architecture decision records (ADRs)
42
+
- Component interaction diagrams and sequence diagrams
43
+
- Infrastructure architecture and network topology
44
+
- Security architecture and authentication flows
45
+
46
+
2. **operations** - Operational procedures and runbooks including:
47
+
- Deployment procedures and release processes
48
+
- Troubleshooting guides and incident response playbooks
49
+
- Monitoring and alerting setup documentation
50
+
- Backup and recovery procedures
51
+
- Configuration management and environment setup
52
+
- Maintenance schedules and operational checklists
53
+
- On-call procedures and escalation paths
54
+
55
+
3. **other** - All other documentation including:
56
+
- Meeting notes and minutes
57
+
- Project plans and timelines
58
+
- Training materials and user guides
59
+
- General reference documents
60
+
- Administrative documentation
61
+
62
+
TASK:
63
+
64
+
For each file, analyze its content and provide:
65
+
- **category**: One of "architecture", "operations", or "other"
66
+
- **metadata**:
67
+
- **filename**: The name of the file
68
+
- **system**: The primary system, service, or component the document relates to
69
+
- **keywords**: A list of relevant technical keywords or topics covered
70
+
71
+
Base your categorization on the document's primary purpose and content. If a document covers multiple areas, choose the category that best represents its main focus.
72
+
"""
73
+
)
74
+
75
+
@app.entrypoint
76
+
defstrands_agent_bedrock(payload):
77
+
"""
78
+
Invoke the agent with a payload and return structured output
0 commit comments