Inspired by isitsnowinginpdx.com. See blog post for more details.
This is a workflow that:
- Gets the current website status for a specified location
- Hits the open weather map API to get the current weather conditions
- If #1 and #2 are different 👉🏻 update the website with the current weather conditions
My deployment of this site is here.
The weather is happening site looks like this
The weather is not happening site looks like this
- AWS
- Route53 - only if using a custom domain
- Certificate Manger - only if using a custom domain
- S3
- CloudFront
- Step Functions
- Systems Manager Parameter Store
- Lambda
- EventBridge Scheduler
- IAM
- CDK
- Node.js - specific version is in
.nvmrc
file - TypeScript
- Open Weather API
- Install Node.js. See
.nvmrc
for the recommended version - Ensure you have an AWS account, install the AWS CLI, and configure your credentials
- Get an API key from Open Weather Map
- Clone the repo
- Create a Secret in Secrets Manager titled
weather-site-api-key
with a plaintext secret value that is your OpenWeather API key. Save the secret ARN for step #2. - Copy
.env.example
to.env
. Fill in the missingSECRETS_EXTENSION_ARN
using the commented URL in.env.example
to grab the correct ARN for your region. Add your copied ARN from the secret you created in step #1 forWEATHER_SECRET_ARN
. Uncomment and add an email address toALERT_EMAIL
, if you'd like to receive an email notification if the state machine has two failed executions within 1 hour (totally optional). Update any other values if you don't want the default values. - Run
npm install
- Run
export AWS_PROFILE=<your_aws_profile>
- Optional if you have a default profile or use
--profile
instead
- Optional if you have a default profile or use
- Run
npm run deploy
see note below about custom domains before running this - If not using a custom domain, the generated CloudFront URL will output to the console. This is where your website is.
- If your domain is not hosted in Route53, you'll also need to point your nameservers at Route53. Directions here
- Non Route53 hosted domain DNS validation is a bit tricky since we're also creating the hosted zone in the creation of this stack. Once the initial deploy starts and the hosted zone is created, I had to quickly updated my nameservers in my domain registrar to point at Route53 (nameservers found in the AWS console looking at the hosted zone - see prior link for more details) to prevent things from failing. This may or may not be your experience. Also note that certificate validation can take up to 30 min according to AWS, so be patient (mine took 20 min).
- This will create the settings needed for both the
www
and non-www versions of your domain to point to the CloudFront distribution. Thewww
version of the domain will redirect to the non-www version of the domain. - Certificates used for CloudFront have to be in the
us-east-1
region. I could've set this up with cross region references, but decided to throw an error for now if a domain name is present and not deploying intous-east-1
. Contributions are welcome to make this better!
If you want to delete the resources created by this project, run npm run destroy
. Delete the secret that you created in the Secrets Manager console.
There's some super basic tests in the test
folder. To run them, run npm run test
.
See CONTRIBUTING.md for more info on our guidelines.