Integration of generator AI capabilities drives transformative change across many industries. Although weather information can be accessed through multiple channels, businesses that rely heavily on weather data can effectively manage and use these key insights and reduce manual processes, providing a robust and scalable solution It requires. This solution demonstrates how to create an AI-driven virtual meteorologist who can answer complex weather-related queries in natural language. Deploy a complete solution that can be used to interact with APIs that provide real-time weather information using a variety of AWS services. This solution uses an Amazon Bedrock agent.
Amazon Bedrock Agent helps streamline workflows and automate recurring tasks. Amazon Bedrock agents can securely connect to your company’s data sources and enhance user requests with accurate responses. You can use Amazon Bedrock agents to architect an action schema tailored to your requirements, allowing controls every time the agent initiates a specified action. This versatile approach will seamlessly integrate and execute business logic within your preferred back-end service, encouraging a cohesive combination of functionality and flexibility. It also has memory retention throughout the interaction, allowing for a more personalized user experience.
This post presents a streamlined approach to deploying AI-powered agents by combining Amazon Bedrock agents with basic models (FM). It guides you through the process of configuring agents and implementing the specific logic needed to provide accurate weather-related answers for virtual meteorologists. Additionally, AWS Amplify to host frontends, AWS lambda functions to handle request logic, Amazon cognito for user authentication, and AWS Identity and Access Management (IAM) to control access to agents , uses a variety of AWS services.
Solution overview
This diagram provides an overview and highlights the key components. The architecture uses Amazon Cognito for user authentication and amplifies it as a hosting environment for front-end applications. Amazon Bedrock’s agents forward details from user queries to action groups and invoke custom Lambda functions. Each action group and lambda function handle a specific task.
- Geographic coordinates – Processing geographic coordinates (geographic coordinates) to get details of a particular location
- weather – Collect weather information for the locations provided
- date – – Gets the current date and time
Prerequisites
To complete the solution in this post, you need to prepare it as follows:
Deploy solution resources using AWS CloudFormation
When you run the AWS CloudFormation template, the following resources will be deployed (note that there will be costs for the AWS resources used):
- Amazon Cognito Resources:
- Lambda Resources:
- Functions –
<Stack name>-geo-coordinates-<auto-generated>
- Functions –
<Stack name>-weather-<auto-generated>
- Functions –
<Stack name>-date-time-<auto-generated>
- Functions –
- Amazon Bedrock Agent: Virtual-Meteorologist
- Action Group (1) –
obtain-latitude-longitude-from-place-name
- Action Group (2) –
obtain-weather-information-with-coordinates
- Action Group (3) –
get-current-date-time-from-timezone
- Action Group (1) –
Once you have expanded the CloudFormation template, copy it as follows: output A tab in the CloudFormation console to use during application configuration after being deployed to AWS Amplify.
AWSRegion
BedrockAgentAliasId
BedrockAgentId
BedrockAgentName
IdentityPoolId
UserPoolClientId
UserPoolId
Deploy the AWS Amplify application
You will need to manually deploy the Amplify application using the frontend code available on GitHub. Complete the following steps:
- Download the frontend code AWS-Amplify-frontend.zip from GitHub.
- Use a .zip file to manually deploy the application to Amplify.
- Return to the Amplify page and access the application using the automatically generated domain.
Use Amazon Cognito for user authentication
Amazon Cognito is an identity service that you can use to authenticate and authorize users. Use Amazon Cognito in your solution to validate users before using your application. It also uses Identity Pool to provide users with temporary AWS credentials while interacting with the Amazon Bedrock API.
Use Amazon bedrock agents to automate application tasks
Amazon Bedrock Agent allows you to build and configure autonomous agents in your applications. Agents help end users complete actions based on organizational data and user input. Agents coordinate interactions between FMS, data sources, software applications, and user conversations.
Use Action Groups to define the actions that the Amazon Bedrock agent performs
Action groups define a set of related actions that the Amazon Bedrock agent can take to assist users. When you configure an action group, you have the option to process the information that users provide. This can include adding user input to the agent’s action group, passing data to a LAMBDA function in custom business logic, or returning controls directly via an InvokeAgent response. The application creates three action groups to provide these important features to the Amazon Bedrock agent. Gets the coordinates of a specific location, get current date and time information, and get weather data for a specific location. These action groups allow agents to access and process critical information, increasing their ability to accurately and comprehensively respond to user queries related to location-based services and weather conditions.
Use Lambda for Amazon Bedrock Action Group
As part of this solution, three Lambda functions are deployed to support action groups defined for the Amazon Bedrock agent.
- Location coordinate lambda function – This function is triggered by
obtain-latitude-longitude-from-place-name
Action group. Takes a place name as input and returns the corresponding latitude and longitude coordinates. This function performs this lookup using a geocoding service or a database. - Date and Time Lambda Functions – was called by
get-current-date-time-from-timezone
Action Group, this function provides current date and time information. - Weather Information Lambda Function – This function is called by
obtain-weather-information-with-coordinates
Action group. Accepts the geographic coordinates from the first lambda function and returns the current weather conditions and predictions for the specified region. This lambda function used the weather API to obtain the latest weather data.
Each of these Lambda functions receives input events that contain related metadata and population type fields from API operations or function parameters in the Amazon Bedrock agent. The function processes this input, performs a specific task, and returns a response using the required information. This response is used by the Amazon Bedrock agent to develop a reply to the user’s query. By using these Lambda functions, Amazon Bedrock agents gain the ability to access external data sources and perform complex calculations, and to handle user requests related to location, time, and weather information. It greatly improves functionality.
Use AWS Amplify for frontend code
Amplify provides a development environment for building secure, scalable mobile and web applications. Developers can focus on their code rather than worrying about the underlying infrastructure. Amplify is also integrated with many GIT providers. In this solution, you use the methods mentioned earlier in this post to manually upload your frontend code.
Application Walkthrough
You will be taken to the URL provided after creating the application in Amplify. When you access the application URL, you will be asked to provide information related to Amazon Cognito and Amazon Bedrock agents. This information is needed to securely authenticate users and enable the front-end to interact with Amazon bedrock agents. Your application can manage user sessions and make approved API calls to AWS services on your behalf.
You can enter information using the values collected from the CloudFormation stack output. You must enter the following fields as shown in the following screenshot:
- User pool ID
- User Pool ClientID
- ID Pool ID
- region
- Agent name
- Agent ID
- Agent Alias ID
- region
You must sign in with your username and password. A temporary password was automatically generated during deployment and sent to the email address provided when launching the CloudFormation template. On your first sign-in attempt, you will be asked to reset your password, as shown in the following video:
Now you can start asking questions in the application. For example, “Can I have a BBQ in Dallas, Texas today?” in seconds, the application will provide detailed results if you can do a BBQ in Dallas, Texas. The following video shows this chat.
Examples of use cases
Below are some sample queries to demonstrate the capabilities of virtual meteorologists:
- “What’s the weather like in New York City today?”
- “Do I need to plan an outdoor birthday party in Miami next weekend?”
- “Is it snowing in Denver on Christmas Day?”
- “Can I go for a swim on the beaches in Chicago today?
These queries show the agent’s ability to provide current weather information, provide advice based on weather forecasts, and predict future weather conditions. You can also ask questions related to activities such as swimming. Also, if the activity is OK, we will answer based on weather conditions.
cleaning
If you decide to discontinue using a virtual meteorologist, follow these steps to remove it, related resources deployed using AWS CloudFormation, and Amplify Deployment:
- Delete the CloudFormation stack:
- In the AWS CloudFormation console, select stack In the navigation pane.
- Find the stack you created during the deployment process (we assigned a name).
- Select and select a stack erase.
- Delete the Amplify application and its resources. See Cleanup Resources for instructions.
Conclusion
This solution demonstrates the power to combine Amazon bedrock agents with other AWS services to create intelligent conversation weather assistants. Using AI and cloud technologies, businesses can automate complex queries and provide valuable insights to their users.
Additional resources
For more information about Amazon Bedrock, see the following resources:
For more information about Anthropic’s Claude 3.5 Sonnet model, see the following resources:
About the author
Salman Ahmed I am Senior Technical Account Manager at AWS Enterprise Support. He enjoys helping travel and hospitality industry customers design, implement and support cloud infrastructure. Passionate about networking services and years of experience, he helps his clients adopt a variety of AWS networking services. Outside of work, Salman takes photos, travels and looks at his favourite sports teams.
Sergio Baraza He is AWS Senior Enterprise Support Lead, helping energy customers design and optimize cloud solutions. Passionate about software development, he guides energy customers through the adoption of AWS services. In external work, Sergio is a multi-instrument musician who plays guitar, piano and drums, and also practices Wingchung Kung Fu.
Rabbi Kumar He is Senior Technical Account Manager at AWS Enterprise Support, helping travel and hospitality customers streamline AWS cloud operations. He is a results-driven IT professional with over 20 years of experience. During a free time, the rabbis enjoy creative activities like painting. He also likes to play cricket and travel to new places.
Ankush Goyal He is the enterprise support lead for AWS Enterprise Support, helping you streamline cloud operations on AWS. He is a results-driven IT professional with over 20 years of experience.