This repo is the "data fetcher" part of the weather monitor. It is comprised of a Lambda function and EventBridge. The Lambda function pulls weather data from api.openweathermap.org and sends the retrieved data to EventBridge.
The lambda function is developed and tested on local machine. Once commited to GitHub, GitHub actions will deploy to AWS using SAM. SAM will also create an EventBridge schedule and necessary IAM role to trigger Lambda periodically.
SAM will push to multiple AWS accounts using assume role.
For Tools Account to be able to assume role, the IAM role needs to give permission to Tools Account.
I also created two environments on GitHub to store credentials. So when SAM deploys, it will grab necessary credentials depending on which environment it is in.
.github/workflows/production.yml
Specifying prod environment, GitHub actions will pull credentials from prod.
.github/workflows/staging.yml
Specifying staging environment, GitHub actions will pull credentials from staging.
Next SAM will assume role to deploy to prod and staging.
template.yaml
Let's go through the important part in SAM template.
This part creates a Lambda function and gives it permission to push events to EventBridge.
This part creates an EventBridge scheduler and gives it necessary permission to invoke Lambda.