Hustlin is a project I created to let me know when there is a home baseball game happening. I get notifications every morning so I can plan my day around not using public transportation before, after, or during baseball games.
The code for the front-end react app can be found at bdougie/hustlin-react and mobile app at bdougie/HusslnMobile.
This is an example of creating a function that runs as a cron job using the serverless schedule
event. It retrieves weather information at 10am (UTC) and emails it to a predefined recipient. For more information on schedule
event check out the Serverless docs on schedule.
cron(Minutes Hours Day-of-month Month Day-of-week Year)
All fields are required and time zone is UTC only.
Field | Values | Wildcards |
---|---|---|
Minutes | 0-59 | , - * / |
Hours | 0-23 | , - * / |
Day-of-month | 1-31 | , - * ? / L W |
Month | 1-12 or JAN-DEC | , - * / |
Day-of-week | 1-7 or SUN-SAT | , - * ? / L # |
Year | 1970-2199 | , - * / |
Read the AWS cron expression syntax docs for more info on how to setup cron
Please visit https://postmarkapp.com to register for a free Postmark account.
Upon setting up access to both external services, you'll be required to update the environment variables in serverless.yml
:
environment:
RECIPIENT: [email protected]
POSTMARK_API_KEY: abc123
POSTMARK_SENDER: [email protected]
In order to deploy the you endpoint simply run
serverless deploy
The expected result should be similar to:
Serverless: Packaging service...
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading service .zip file to S3 (1.87 MB)...
Serverless: Updating Stack...
Serverless: Checking Stack update progress...
...........
Serverless: Stack update finished...
Serverless: Removing old service versions...
Service Information
service: scheduled-weather-example
stage: dev
region: us-east-1
api keys:
None
endpoints:
None
functions:
email: arn:aws:lambda:us-east-1:219106525755:function:serverless-scheduled-hustlin
There is no additional step required. Your defined schedule becomes active right away after deployment.
To test your function remotely:
sls invoke -f email
The expected result should be similar to:
{
"success": true
}