Artificial Intelligence

Build AI agents with Amazon Bedrock AgentCore using AWS CloudFormation

Agentic-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 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 the environments to help prevent unpredictable agent behavior. It provides version control and rollback capabilities for quick recovery from issues, essential for maintaining agentic system availability, and enables automated scaling and resource optimization through parameterized templates that adapt from lightweight development to production-grade deployments. For agentic applications operating with minimal human intervention, the reliability of IaC, automated validation of security standards, and seamless integration into DevOps workflows are essential for robust autonomous operations.

In order to streamline the resource deployment and management, Amazon Bedrock AgentCore services are now being supported by various IaC frameworks such as AWS Cloud Development Kit (AWS CDK), Terraform and AWS CloudFormation Templates. This integration brings the power of IaC directly to 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 CDK and Terraform can be found at GitHub Sample Library.

Building an activity planner agent based on weather

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

  • Real-time weather data collection – The application retrieves current weather conditions from authoritative meteorological sources such as weather.gov, gathering 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 suitability of a day for an outdoor activity based on multiple weather factors:
    • Temperature comfort scoring – Activities receive reduced suitability scores when temperatures drop below 50°F
    • Precipitation risk assessment – Rain probabilities exceeding 30% trigger adjustments to outdoor activity recommendations
    • Wind condition impact evaluation – Wind speeds above 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 look at how this can be implemented using AgentCore services:

  • AgentCore Browser – For automated browsing of weather data from sources such as weather.gov
  • AgentCore Code Interpreter – For executing Python code that processes weather data, performs calculations, and implements the scoring algorithms
  • AgentCore Runtime – For hosting an agent that orchestrates the application flow, managing data processing pipelines, and coordinating between different components
  • AgentCore Memory – For storing the user preferences as long term memory

The following diagram shows this architecture.

Deploying the CloudFormation template

  1. Download the CloudFormation template from github for End-to-End-Weather-Agent.yaml on your local machine
  2. Open CloudFormation from AWS Console
  3. Click Create stack → With new resources (standard)
  4. Choose template source (upload file) and select your template
  5. Enter stack name and change any required parameters if needed
  6. Review configuration and acknowledge IAM capabilities
  7. Click Submit and monitor deployment progress on the Events tab

Here is the visual steps for CloudFomation template deployment

Running and testing the application

Adding observability and monitoring

AgentCore Observability provides key advantages. It offers quality and trust through detailed workflow visualizations and real-time performance monitoring. You can gain accelerated time-to-market by using Amazon CloudWatch powered dashboards that reduce manual data integration from multiple sources, making it possible to take corrective actions based on actionable insights. Integration flexibility with OpenTelemetry-compatible format supports existing tools such as CloudWatchDataDogArize PhoenixLangSmith, and LangFuse.

The service provides end-to-end traceability across frameworks and foundation models (FMs), captures critical metrics such as token usage and tool selection patterns, and supports both automatic instrumentation for AgentCore Runtime hosted agents and configurable monitoring for agents deployed on other services. This comprehensive observability approach helps organizations achieve faster development cycles, more reliable agent behavior, and improved operational visibility while building trustworthy AI agents at scale.

The following screenshot shows metrics in the AgentCore Runtime UI.

Customizing for your use case

The weather activity planner AWS CloudFormation template is designed with modular components that can be seamlessly adapted for various applications. For instance, 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), adjust the AgentCore Memory component to store relevant user preferences or business context (such as customer profiles, inventory levels, or project requirements), and reconfigure the Strands Agents tasks to orchestrate workflows specific to your domain (such as supply chain optimization, customer service automation, or compliance monitoring).

Best practices for deployments

We recommend the following practices for your deployments:

  • Modular component architecture – Design AWS CloudFormation templates with separate sections for each AWS Services.
  • Parameterized template design – Use AWS CloudFormation parameters for the 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 – Implement fine-grained IAM roles for each AgentCore component with specific resource Amazon Resource Names (ARNs). Refer to our documentation on AgentCore security considerations.
  • Comprehensive monitoring and observability – Enable CloudWatch logging, custom metrics, AWS X-Ray distributed tracing, and alerts across the components.
  • Version control and continuous integration and continuous delivery (CI/CD) integration – Maintain templates in GitHub with automated validation, comprehensive testing, and AWS CloudFormation StackSets for consistent multi-Region deployments.

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

Clean up resources

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

  1. On the Amazon S3 console, manually delete the contents inside the bucket you created for template deployment and then delete the bucket.
  2. On the CloudFormation console, choose Stacks in the navigation pane, select the main stack, and choose Delete.

Conclusion

In this post, we introduced an automated solution for deploying AgentCore services using AWS CloudFormation. These preconfigured 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 deployments so you can focus on building agentic AI workflows that drive business growth.

Try out some more examples from our Infrastructure as Code sample repositories :


About the authors

Chintan Patel is a Senior Solution Architect at AWS with extensive experience in solution design and development. He helps organizations across diverse industries to modernize their infrastructure, demystify Generative AI technologies, and optimize their cloud investments. Outside of work, he enjoys spending time with his kids, playing pickleball, and experimenting with AI tools.

Shreyas Subramanian is a Principal Data Scientist and helps customers by using Generative AI and deep learning to solve their business challenges using AWS services like Amazon Bedrock and AgentCore. Dr. Subramanian contributes to cutting-edge research in deep learning, Agentic AI, foundation models and optimization techniques with several books, papers and patents to his name. In his current role at Amazon, Dr. Subramanian works with various science leaders and research teams within and outside Amazon, helping to guide customers to best leverage state-of-the-art algorithms and techniques to solve business critical problems. Outside AWS, Dr. Subramanian is a expert reviewer for AI papers and funding via organizations like Neurips, ICML, ICLR, NASA and NSF.

Kosti Vasilakakis is a Principal PM at AWS on the Agentic AI team, where he has led the design and development of several Bedrock AgentCore services from the ground up, including Runtime. He previously worked on Amazon SageMaker since its early days, launching AI/ML capabilities now used by thousands of companies worldwide. Earlier in his career, Kosti was a data scientist. Outside of work, he builds personal productivity automations, plays tennis, and explores the wilderness with his family.