This project retrieves values for stock and bond ticker and stores them in a Google Spreadsheet.
I use it as a fallback to the GOOGLEFINANCE(...) Google Spreadhseet function, which can be unstable
(especially for stock exchanges other than NYSE).
Contact the me for any further info.
The stack requires two mandatory parameters and two optional ones.
- Command line parameters (CDK context)
- Environment variables (from
.envfile if present)
npx cdk deploy \
-c googleSpreadsheetId=YOUR_SPREADSHEET_ID \
-c alertEmail=your-email@example.com \
-c failureThreshold=3 \
-c pollIntervalHours=2Create a .env file in the project root:
GOOGLE_SPREADSHEET_ID=your_spreadsheet_id_here
ALERT_EMAIL=your-email@example.com
# Optional — alerting behaviour (defaults shown)
FAILURE_THRESHOLD=3 # consecutive failing runs before alerting
POLL_INTERVAL_HOURS=2 # run interval in hours; also sets the alarm evaluation window
Then deploy:
npx cdk deployThe stack alerts only when a specific ticker fails consistently across multiple runs, ignoring transient errors.
How it works:
- The ticker Lambda logs a structured
ERRORentry (including thetickerfield) whenever a ticker cannot be fetched or updated. - A CloudWatch Metric Filter counts these errors and feeds a CloudWatch Alarm with a 5-minute evaluation window.
- The alarm fires within ~5 minutes of any run that produces errors, then resets automatically — well before the next scheduled run. It acts purely as a reactive trigger, not a consecutive-failure detector.
- Each alarm trigger invokes an Alerting Lambda via EventBridge. The Lambda runs a CloudWatch Logs Insights query over the last
failureThreshold × pollIntervalHourshours (default: 6h) and counts errors per ticker. - If any ticker has accumulated ≥
failureThresholderrors in that window, a notification email is sent with the ticker name and last error message. - If no ticker exceeds the threshold (e.g. different tickers failed in each run), the Lambda exits silently — no email sent.
Scenarios:
- 3 different tickers each fail once: alarm fires, but no single ticker has ≥ 3 errors in the query window → no email.
- Same ticker fails 3 consecutive runs: alarm fires on each run; by the third, the Logs Insights query finds ≥ 3 errors for that ticker → email sent.
- Ticker recovers after 3 failures: alarm fires no more (no errors in subsequent runs) → emails stop automatically.
Tuning:
- Increase
failureThresholdto require more consecutive failures before alerting. pollIntervalHourscontrols both the EventBridge schedule and the query window size (failureThreshold × pollIntervalHourshours).
You can run the update process locally without deploying to AWS.
Add the following to your .env file:
GOOGLE_SPREADSHEET_ID=your_spreadsheet_id_here
GOOGLE_CREDENTIALS_FILE=/path/to/service-account.json
GOOGLE_CREDENTIALS_FILE should point to a Google service account JSON key file with access to the spreadsheet.
Run the full update (all tickers):
npm run run-localPreview what would be written without modifying the spreadsheet:
npm run run-local:dryTarget a single ticker:
npm run run-local -- --ticker BTC-USD
npm run run-local:dry -- --ticker BTC-USDEnable debug logging:
POWERTOOLS_LOG_LEVEL=DEBUG npm run run-local:drynpx cdk deploydeploy this stack to your default AWS account/regionnpx cdk diffcompare deployed stack with current statenpx cdk synthemits the synthesized CloudFormation template