/aws-microservice-data-fetcher

this is a fork from konami99

Primary LanguageTypeScript

Weather data fetcher

weather_monitor drawio

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.

Deploying to multi-accounts on AWS

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. Screen Shot 2023-09-03 at 5 41 12 pm

For Tools Account to be able to assume role, the IAM role needs to give permission to Tools Account. Screen Shot 2023-09-03 at 5 43 15 pm

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. Screen Shot 2023-09-03 at 6 05 59 pm

.github/workflows/production.yml

Specifying prod environment, GitHub actions will pull credentials from prod. Screen Shot 2023-09-03 at 6 08 56 pm

.github/workflows/staging.yml

Specifying staging environment, GitHub actions will pull credentials from staging. Screen Shot 2023-09-03 at 6 09 44 pm

Next SAM will assume role to deploy to prod and staging. Screen Shot 2023-09-03 at 6 14 56 pm

SAM template

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. Screen Shot 2023-09-03 at 6 19 20 pm

This part creates an EventBridge scheduler and gives it necessary permission to invoke Lambda. Screen Shot 2023-09-03 at 6 21 40 pm