---
# System prepended metadata

title: Chatbot Weather App with Amazon Lex & AWS Lambda

---



---


---
# Chatbot Weather App with Amazon Lex & AWS Lambda

## Overview
This project extends my **Serverless Weather App** by integrating it with **Amazon Lex** to provide a conversational chatbot interface.  
The chatbot understands natural language queries like *“What’s the weather in Lagos tomorrow?”* and returns real-time weather information.  
It captures two slots:  
- **City** → the location to check weather for.  
- **Date** → the day (today, tomorrow or an actual date like `2025-08-19`) for the weather forecast.  


## Steps Taken

### 1. Create Amazon Lex Bot
- Created a bot called **WeatherBot**.  
- Added an intent named **GetWeather**.  
- Configured **slots**:  
  - `City` (slot type `AMAZON.City`).  
  - `Date` (slot type `AMAZON.Date`).  
- Defined **sample utterances**:  
  - "What’s the weather in {City} today?"  
  - "Tell me the weather in {City} tomorrow."  
  - "What’s the weather in {City} , {Date} ?"  
- Enabled **Fulfillment and Code hook** so that Lex calls the Lambda function when the intent is triggered.  
 ### 2. Integrate Lex with AWS Lambda
- Created a **Python Lambda function** to handle requests from Lex.  
- The Lambda function does the following:  
  1. Extracts the `City` and `Date` slots from the Lex input event.    
  2. Formats the weather data into a natural-language response.  
  3. Returns the response back to Lex.  

> **Note:** The Lambda code file is named `lambda_handler.py`.  
> Handler configured as:  
> ```
> lambda_handler.lambda_handler


## Challenges & Solutions

- **Challenge:** While integrating Lambda with Lex, the connection failed.  
  - The issue was that the bot was not configured with the correct **Language (English)** and **Lex V2 version**.  
  - While reading the AWS documentation i didn't get the solution on time, so troubleshooting took extra time.  

- **Solution:** Fixed by explicitly setting **Language = English** and selecting the **latest Lex V2 version**.  
  - After this, the integration worked correctly.  

---

- **Challenge:** Slot formatting was very strict.  
  - Example:  
    - ❌ `What’s the weather in {Location}, {Date}?` → caused errors.  
    - ✅ `What’s the weather in {Location} , {Date} ?` → worked.  

- **Solution:** I learned that **spacing and punctuation in utterances matter a lot** in Lex. Double-checking patterns fixed the problem.

---

## Key Learnings
- **Amazon Lex** makes it simple to create conversational chatbots without building NLP from scratch.  
- **Slots** in Lex allow capturing structured data like cities and dates from natural queries.  
- **Lambda integration** provides flexibility to connect with external APIs.  
- Small details (like bot language and utterance formatting) can make or break integration. 

## Example Test
**User**: What's the weather in New York today?
**Bot**: The temperature in New York today is 25°C with clear skies.

**User**: What's the weather in Lagos tomorrow?
**Bot**: The temperature in Lagos tomorrow will be 30°C with scattered clouds

## Code Repository

🔗 GitHub Repo – https://github.com/samaj806/aws-weather-app.git