# Serverless Weather App with AWS Lambda & HTTP API ## Overview This project demonstrates how i built a **serverless application** to fetch real-time weather data using **AWS Lambda** and **API Gateway (HTTP API)**. The app integrates with the **OpenWeatherMap API** and returns the current temperature and conditions for a given city. --- ## Architecture - **API Gateway (HTTP API)** → Provides a lightweight endpoint for client requests. - **AWS Lambda (Python)** → Fetches weather data from OpenWeatherMap API. - **OpenWeatherMap API** → External provider of weather information. - **CloudWatch Logs** → For monitoring and debugging Lambda executions. --- ## Steps Taken ### 1. Create AWS Lambda Function - Wrote a **Python Lambda function** to query the OpenWeatherMap API. - Used the `requests` library to make HTTP calls. - Installed the requests library locally using `vscode`. - Opened `vscode` and created a folder for the project (weather-app). - Inside the folder open the terminal and run the following command: `python -m venv venv.` - Activated the virtual environment on windows: `venv\scripts\activate.` - Installed the requests library inside the virtual environment using: `pip install requests.` - After installing requests, navigate to `venv\lib\site-packages.` - Copied all the content and paste them into the weather app project folder: `xcopy requests \* C:\path\to\your\project-folder\ /E /I` - Created a zip file containing all the content in the project folder. - Upload to AWS Lambda. - > **Note:** The Lambda code file is named `lambda_handler.py` (instead of the default `lambda_function.py`). > The handler is defined as: > ``` > lambda_handler.lambda_handler > ``` > - First part → `lambda_handler` = the filename. > - Second part → `lambda_handler` = the function name inside the file. - ### 2. Set Up API Gateway HTTP API - Created an **HTTP API** in API Gateway. - Integrated the API with the Lambda function. - Configured a route `/weather` with a query string parameter `city`. - Deployed the API to a stage (e.g., `dev`). ### 3. Test the Application - Called the API endpoint with: - https://{api_id}.execute-api.us-east-1.amazonaws.com/weather?city=London - Response returned the current **temperature** and **weather condition** for the city. --- ## Verification - Successfully retrieved weather data for multiple cities. - Confirmed Lambda execution and debugging via **CloudWatch Logs**. --- ## Key Learnings - **AWS Lambda** allows building event-driven applications without managing servers. - **HTTP APIs** are simpler and cheaper compared to REST APIs, making them great for lightweight services. - Using **environment variables** ensures secure handling of API keys. ## Code Repository 🔗 GitHub Repo – https://github.com/samaj806/aws-weather-app.git