
Provisioning AdminZero: Infrastructure as Code for Serverless AI Agents
Transitioning from architectural blueprints to concrete infrastructure. Explore how to provision Amazon Bedrock agents, DynamoDB tables, and Lambda action groups using Terraform.
Over the past few weeks, we’ve mapped out AdminZero’s core architecture, engineered its OpenAPI schemas, and structured its prompt reasoning loops and error defenses. Now, it’s time to move from theory to reality by provisioning the actual infrastructure.
When deploying AI agents on AWS, managing resources manually through the console quickly leads to drift and configuration errors. Instead, we use Terraform to define our entire serverless stack as reproducible code.
Here is how we provision the foundational AWS infrastructure for AdminZero before connecting our Python runtime handlers.
1. Defining the Core State Store (DynamoDB)
AdminZero needs a low-latency state store to track active subscriptions and in-flight administrative tasks. We provision a single DynamoDB table using Terraform:
resource "aws_dynamodb_table" "admin_zero_state" { name = "AdminZeroState" billing_mode = "PAY_PER_REQUEST" hash_key = "PK" range_key = "SK"
attribute { name = "PK" type = "S" }
attribute { name = "SK" type = "S" }
tags = { Environment = "Production" Project = "AdminZero" }}2. Setting Up IAM Roles with Least Privilege
Autonomous agents must operate with tightly scoped permissions. We create an execution role for our Lambda action groups that grants access only to our DynamoDB table and specific S3 buckets:
resource "aws_iam_role" "lambda_execution_role" { name = "AdminZeroLambdaExecutionRole"
assume_role_policy = jsonencode({ Version = "2012-10-17" Statement = [ { Action = "sts:AssumeRole" Effect = "Allow" Principal = { Service = "lambda.amazonaws.com" } } ] })}
resource "aws_iam_role_policy" "lambda_dynamodb_policy" { name = "AdminZeroDynamoDBPolicy" role = aws_iam_role.lambda_execution_role.id
policy = jsonencode({ Version = "2012-10-17" Statement = [ { Effect = "Allow" Action = [ "dynamodb:GetItem", "dynamodb:PutItem", "dynamodb:Query", "dynamodb:UpdateItem" ] Resource = aws_dynamodb_table.admin_zero_state.arn } ] })}3. Packaging the Subscription Analyzer Lambda
With our data layer and security roles in place, we package our deterministic Python Lambda handler. This function receives the parsed statement payload from the Bedrock agent, evaluates recurring cadences, and returns a structured JSON summary.
import jsonimport boto3import os
dynamodb = boto3.resource('dynamodb')table = dynamodb.Table(os.environ['TABLE_NAME'])
def lambda_handler(event, context): """ Evaluates incoming transaction items for recurring patterns. """ agent = event.get('agent', '') action_group = event.get('actionGroup', '') function_name = event.get('function', '') parameters = event.get('parameters', []) # Extract parameters passed by Bedrock Agent user_id = next((p['value'] for p in parameters if p['name'] == 'user_id'), None) if function_name == 'audit_subscriptions': # Business logic for subscription detection response_body = { "application/json": { "body": json.dumps({ "status": "success", "message": "Audited 12 transactions. Found 2 recurring subscriptions.", "subscriptions": [ {"merchant": "CloudStorage Pro", "amount": 9.99, "cadence": "monthly"}, {"merchant": "StreamingPlus", "amount": 14.99, "cadence": "monthly"} ] }) } } return { "messageVersion": "1.0", "response": { "actionGroup": action_group, "function": function_name, "functionResponse": response_body } } return { "statusCode": 400, "body": json.dumps("Invalid function call") }4. Wiring It All Together
In our Terraform
main.tf , we bundle the Python code into a deployment zip and link the Lambda function to Amazon Bedrock as an Action Group:data "archive_file" "lambda_zip" { type = "zip" source_dir = "${path.module}/lambda" output_path = "${path.module}/lambda_function.zip"}
resource "aws_lambda_function" "subscription_analyzer" { filename = data.archive_file.lambda_zip.output_path function_name = "AdminZeroSubscriptionAnalyzer" role = aws_iam_role.lambda_execution_role.arn handler = "index.lambda_handler" runtime = "python3.11" source_code_hash = data.archive_file.lambda_zip.output_base64sha256
environment { variables = { TABLE_NAME = aws_dynamodb_table.admin_zero_state.name } }}Next Steps
By defining our infrastructure as code, we ensure that AdminZero’s data persistence, security posture, and compute layers are cleanly decoupled and ready for scale.
Next up: we boot up the runtime, invoke our Bedrock agent, and watch AdminZero execute its first live audit loop!
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article