This project is a Weather Validator that uses AWS services (Lambda, RDS, S3, and API Gateway, VPC, NAT Gateway, Internet Gateway, etc). The architecture can be seen below:
The application has a frontend component, using HTML, CSS, and JavaScript. The backend is composed of Lambda functions written in Java. The database is an RDS PostgreSQL instance.
For Local Development (requires a LocalStack for AWS license):
- Docker
- Java 21
- Maven (3.9.9)
- Node.js (v23.5.0)
- Terraform (v1.9.3)
lstkCLI, installed vianpm install -g @localstack/lstkorbrew install localstack/tap/lstk- AWS CLI (required by
lstk aws) - Open Weather API key (free tier) - to include in terraform/variables.tf and terraform-local/variables.tf
- A valid LocalStack for AWS license. Your license provides a
LOCALSTACK_AUTH_TOKENto activate LocalStack.
For Deployment to AWS:
- AWS CLI
- Terraform (v1.9.3)
Before proceeding, make sure you have the AWS CLI configured with the necessary permissions (use aws configure). Additionally, your account will need a user with AdministratorAccess policy attached.
In other words:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "*",
"Resource": "*"
}
]
}For a fast and easy deployment, you can use the following steps.
The Lambda jar files are already included in the project.
cd terraform
terraform init
terraform plan
terraform apply --auto-approveOnce this is done, you will need to run the following command to create the database tables:
aws lambda invoke --function-name db-setup --region us-east-1 output.json See the CloudFront URL in the output of the Terraform run. You can access the application using this URL. That's it! You have successfully deployed the Weather Validator project to AWS.
Backend:
- change java files in the
backenddirectory - run
mvn clean installin thebackenddirectory - run
aws lambda update-function-code --function-name history-lambda --zip-file fileb://history-lambda/target/history-lambda-1.0.0.jar- change according to the function you are updating
Frontend:
- change files in the
frontenddirectory - run
aws s3 sync ./ s3://weather-validator-bucketin thefrontenddirectory
Infrastructure:
- change
.tffiles in theterraformdirectory - run
terraform apply --auto-approvein theterraformdirectory
cd backend
mvn clean installInstall http-server:
npm install --global http-serveror
brew install http-serverThen:
cd frontend
http-serverYou can change the files as needed. The frontend will be available at http://localhost:8080.
Start LocalStack for AWS with the LOCALSTACK_AUTH_TOKEN pre-configured:
export LOCALSTACK_AUTH_TOKEN=<your-auth-token>
LOCALSTACK_DEBUG=1 lstk startDeploy Infrastructure Locally:
Run the following commands:
cd terraform-local
lstk tf init
lstk tf apply --auto-approveOnce this is done, you will need to run the following command to create the database tables:
lstk aws lambda invoke --function-name db-setup --region us-east-1 output.json or
aws --endpoint=http://localhost.localstack.cloud:4566 lambda invoke --function-name db-setup --region us-east-1 output.jsonNote!
It could happen that the lstk tf apply executes successfully, but the resources are not ready yet, hence the endpoints will not be available to pass to the Lambdas and environment variables.
Check the terraform.tfstate file, particularly for the HOST environment variable in the aws_lambda_function resources.
It holds the RDS Proxy endpoint and port. In terraform-local the port is the cluster port, since LocalStack serves the database on the cluster port instead of 5432.
In this case, please run the command again. You will see that a few resources have changed:
Apply complete! Resources: 0 added, 8 changed, 0 destroyed.With LocalStack running, build, deploy and test with:
make build
make deploy
make testmake test creates the tables with db-setup, checks the weather for a city through API Gateway, and reads the stored check back from the history API.
To run without an OpenWeather API key, point the weather Lambda at a stub before deploying.
The test then serves the responses in tests/fixtures from S3 and checks both verdicts:
export TF_VAR_open_weather_base_url=http://localhost.localstack.cloud:4566/weather-stub/weather.json
make deploy
make testWithout the stub, make test calls the real OpenWeather API for London (override with CITY=<name>).
In the Check Weather tab, you can enter a city name and click the "Get Weather" button. The application will display the weather for the city you entered, along with the verdict: the weather must be over 20 degrees Celsius with no clouds. Otherwise, the application will display a message saying the weather is not nice.
The history tab will display the history of the cities you have checked the weather for. The full data from the Weather API can be copied to the clipboard by clicking the "Copy" button.
- Destroy the cloud resources:
cd terraform
terraform destroy- Destroy local resources:
cd terraform-local
lstk tf destroyOr just shut down the LocalStack container:
lstk stop

