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:
- Docker
- Java 21
- Maven (3.9.9)
- Node.js (v23.5.0)
- Terraform (v1.9.3) + terraform-local
- LocalStack (for local development)
- AWS CLI
- Open Weather API key (free tier) - to include in terraform/variables.tf and terraform-local/variables.tf
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-approve
Once 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
backend
directory - run
mvn clean install
in thebackend
directory - 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
frontend
directory - run
aws s3 sync ./ s3://weather-validator-bucket
in thefrontend
directory
Infrastructure:
- change
.tf
files in theterraform
directory - run
terraform apply --auto-approve
in theterraform
directory
cd backend
mvn clean install
Install http-server
:
npm install --global http-server
or
brew install http-server
Then:
cd frontend
http-server
You can change the files as needed. The frontend will be available at http://localhost:8080
.
After installing the LocalStack CLI (via pip or homebrew), run the following command:
DEBUG=1 localstack start
Deploy Infrastructure Locally:
After installing terraform-local, run the following commands:
cd terraform-local
tflocal init
tflocal apply --auto-approve
Once this is done, you will need to run the following command to create the database tables:
awslocal 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.json
Note!
It could happen that the tflocal 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
and PORT
environment variables in the aws_lambda_function
resource.
These are the endpoint and port for the RDS Proxy instance.
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.
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
tflocal destroy
Or just shut down the LocalStack container:
localstack stop