Build an AI agent with Amazon Bedrock AgentCore using AWS CloudFormation

by
0 comments
Build an AI agent with Amazon Bedrock AgentCore using AWS CloudFormation

Agent-AI has become essential for deploying production-ready AI applications, yet many developers struggle with the complexity of manually configuring agent infrastructure across multiple environments. Infrastructure as code (IaC) facilitates the consistent, secure, and scalable infrastructure that autonomous AI systems require. It minimizes manual configuration errors through automated resource management and declarative templates, reducing deployment time from hours to minutes while facilitating infrastructure consistency across environments to help prevent unexpected agent behavior. It provides version control and rollback capabilities for quick recovery from issues, which is essential to maintaining agentive system availability, and enables automatic scaling and resource optimization through parameterized templates that adapt from lightweight development to production-grade deployment. For agentic applications to operate with minimal human intervention, IaC reliability for robust autonomous operation, automated verification of security standards, and seamless integration into DevOps workflows are essential.

To streamline resource deployment and management, Amazon Bedrock AgentCore services are now being supported by various IaC frameworks such as the AWS Cloud Development Kit (AWS CDK). terraform And AWS CloudFormation templates. This integration brings the power of IaC directly into AgentCore so developers can provision, configure, and manage their AI agent infrastructure. In this post, we use CloudFormation templates to build an end-to-end application for a weather activity planner. Examples of using the CDK and Terraform can be found here GitHub Sample Library.

Building an activity planner agent based on weather

The sample creates a weather activity planner, which demonstrates a practical application that processes real-time weather data to provide personalized activity recommendations based on location of interest. The application includes several integrated components:

  • real time weather data collection – The application retrieves current weather conditions from official meteorological sources such as Weather.gov, collecting essential data points including temperature readings, precipitation probability forecasts, wind speed measurements and other relevant atmospheric conditions that influence outdoor activity suitability.
  • weather analysis engine – The application processes raw meteorological data through customized logic to evaluate a day’s suitability for outdoor activity based on several weather factors:
    • temperature comfort scoring – Activities receive lower suitability scores when temperatures drop below 50°F
    • Precipitation Risk Assessment – Adjustments to recommendations for outdoor activities begin when the chance of rain exceeds 30%
    • air condition impact assessment – Wind speeds over 15 mph affect overall comfort and safety ratings for various activities
  • personalized recommendation system – The application processes weather analysis results with user preferences and location-based awareness to generate tailored activity suggestions.

The following diagram shows this flow.

Now let’s see how this can be implemented using AgentCore services:

  • AgentCore Browser – For automatic browsing of weather data from sources such as Weather.gov
  • agentcore code interpreter – To execute Python code that processes weather data, performs calculations, and applies scoring algorithms
  • agentcore runtime – To host an agent that orchestrates application flow, manages data processing pipelines, and coordinates between different components
  • agentcore memory – To store user preferences as long-term memory

The following figure shows this architecture.

Deploying a CloudFormation template

  1. For this download CloudFormation template from Github end-to-end-weather-agent.yaml on your local machine
  2. Open CloudFormation from the AWS console
  3. Click create stack → With new resources (standard)
  4. Select template source (upload file) and select your template
  5. Enter the stack name and change the required parameters if necessary
  6. Review configuration and accept IAM capabilities
  7. Click submit And monitor deployment progress on the Events tab

Here are the visual steps for CloudFomation template deployment

Running and testing the application

Add observation and monitoring

AgentCore Observability provides key benefits. It provides quality and confidence through detailed workflow visualization and real-time performance monitoring. You can achieve instant time-to-market using Amazon CloudWatch powered dashboards that minimize manual data integration from multiple sources, making it possible to take corrective actions based on actionable insights. Integration flexibility with OpenTelemetry-compliant format supporting existing tools Such as cloudwatch, datadog, get up surprise, langsmithAnd langfuse.

The service provides end-to-end traceability across the framework and Foundation Model (FM), capturing key metrics such as token usage and tool selection patterns, and supporting both automated instrumentation for AgentCore runtime hosted agents and configurable monitoring for agents deployed on other services. This comprehensive overview approach helps organizations achieve faster development cycles, more reliable agent behavior, and better operational visibility while building trustworthy AI agents at scale.

The following screenshot shows metrics in the AgentCore Runtime UI.

Adapt to your use case

The Weather Activity Planner AWS CloudFormation template is designed with modular components that can be seamlessly adapted to different applications. For example, you can customize the AgentCore browser tool to collect information from different web applications (such as financial websites for investment guidance, social media feeds for sentiment monitoring, or ecommerce sites for price tracking), modify the AgentCore code interpreter algorithms to process your specific business logic (such as predictive modeling for sales forecasting, risk assessment for insurance, or quality control for manufacturing), relevant user preferences or business context (such as customer profiles, Adjust the AgentCore memory component to store inventory levels, or project (requirements), and reconfigure strands agent Functions to streamline workflows specific to your domain (such as supply chain optimization, customer service automation, or compliance monitoring).

best practices for deployment

We recommend the following practices for your deployment:

  • modular component architecture – Design AWS CloudFormation templates with separate sections for each AWS services.
  • parameterized template design – Use AWS CloudFormation parameters for configurable elements to facilitate reusable templates across environments. For example, this can help associate the same base container with multiple agent deployments, help point to two different build configurations, or parameterize the LLM of choice for powering your agents.
  • AWS Identity and Access Management (IAM) Security and Least Privilege – Enforce streamlined IAM roles for each AgentCore component with unique Amazon Resource Names (ARNs). See our documentation on AgentCore security considerations.
  • Comprehensive monitoring and observation – Enable CloudWatch logging, custom metrics, AWS X-Ray distributed tracing, and alerts across all components.
  • Version Control and Continuous Integration and Continuous Delivery (CI/CD) integration – Maintain templates in GitHub with automated validation, extensive testing, and AWS CloudFormation stackset for consistent multi-region deployment.

You can find a more comprehensive set of best practices at CloudFormation Best Practices

clear resources

To avoid future charges, remove the resources used in this solution:

  1. On the Amazon S3 console, manually delete the content inside the bucket you created for the template deployment, and then delete the bucket.
  2. On the CloudFormation console, select heap In the navigation pane, select the main stack, and choose delete.

conclusion

In this post, we have introduced an automated solution for deploying AgentCore services using AWS CloudFormation. These pre-configured templates enable rapid deployment of powerful agentic AI systems without the complexity of manual component setup. This automated approach helps save time and facilitates consistent and reproducible deployment so you can focus on building agentic AI workflows that drive business growth.

Try some more examples from our infrastructure as code sample repositories:


About the authors

Chintan Patel Is a Senior Solutions Architect at AWS with extensive experience in solution design and development. He helps organizations across various industries modernize their infrastructure, unleash generative AI technologies, and optimize their cloud investments. Outside of work, he enjoys spending time with his children, playing pickleball, and experimenting with AI tools.

Shreyas Subramanian Is a Principal Data Scientist and helps customers using generative AI and deep learning to solve their business challenges using AWS services like Amazon Bedrock and AgentCore. Dr. Subramanian contributes cutting-edge research in deep learning, agent AI, foundation models, and optimization techniques with numerous books, papers, and patents to his name. In his current role at Amazon, Dr. Subramaniam works with diverse science leaders and research teams inside and outside Amazon, helping guide customers in how to best leverage cutting-edge algorithms and technologies to solve business critical problems. Outside of AWS, Dr. Subramaniam is an expert reviewer for AI papers and funding through organizations such as Neuroscience, ICML, ICLR, NASA, and NSF.

Kosti Vasilkakis is a Principal PM at AWS in the Agentic AI team, where he has led the design and development of many Bedrock AgentCore services from the ground up, including runtimes. He previously worked on Amazon SageMaker from its early days, launching AI/ML capabilities that are now used by thousands of companies worldwide. Early in his career, Costi was a data scientist. Outside of work, he builds personal productivity automation, plays tennis, and explores the woods with his family.

Related Articles

Leave a Comment