|
1 | 1 | # AWS Node Scheduled Cron Example
|
2 | 2 |
|
3 |
| -This is an example of creating a function that runs as a cron job using the serverless `schedule` event. For more information on `schedule` event check out [our docs](https://serverless.com/framework/docs/providers/aws/events/schedule/). |
| 3 | +This is an example of creating a function that runs as a cron job using the serverless `schedule` event. For more information on `schedule` event check out the Serverless docs on [schedule](https://serverless.com/framework/docs/providers/aws/events/schedule/). |
4 | 4 |
|
5 | 5 | Schedule events use the `rate` or `cron` syntax.
|
6 | 6 |
|
@@ -37,14 +37,68 @@ All fields are required and time zone is UTC only.
|
37 | 37 |
|
38 | 38 | Read the [AWS cron expression syntax](http://docs.aws.amazon.com/lambda/latest/dg/tutorial-scheduled-events-schedule-expressions.html) docs for more info on how to setup cron
|
39 | 39 |
|
40 |
| -## Running |
| 40 | +## Deploy |
| 41 | + |
| 42 | +In order to deploy the you endpoint simply run |
| 43 | + |
| 44 | +```bash |
| 45 | +serverless deploy |
| 46 | +``` |
| 47 | + |
| 48 | +The expected result should be similar to: |
| 49 | + |
| 50 | +```bash |
| 51 | +Serverless: Packaging service... |
| 52 | +Serverless: Uploading CloudFormation file to S3... |
| 53 | +Serverless: Uploading service .zip file to S3 (1.47 KB)... |
| 54 | +Serverless: Updating Stack... |
| 55 | +Serverless: Checking Stack update progress... |
| 56 | +.............. |
| 57 | +Serverless: Stack update finished... |
| 58 | + |
| 59 | +Service Information |
| 60 | +service: scheduled-cron-example |
| 61 | +stage: dev |
| 62 | +region: us-east-1 |
| 63 | +api keys: |
| 64 | + None |
| 65 | +endpoints: |
| 66 | + None |
| 67 | +functions: |
| 68 | + scheduled-cron-example-dev-cron: arn:aws:lambda:us-east-1:377024778620:function:scheduled-cron-example-dev-cron |
| 69 | + scheduled-cron-example-dev-secondCron: arn:aws:lambda:us-east-1:377024778620:function:scheduled-cron-example-dev-secondCron |
| 70 | +``` |
| 71 | + |
| 72 | +There is no additional step required. Your defined schedule becomes active right away after deployment. |
| 73 | + |
| 74 | +## Usage |
41 | 75 |
|
42 | 76 | To see your cron job running tail your logs with:
|
43 | 77 |
|
44 | 78 | ```bash
|
45 | 79 | serverless logs --function cron --tail
|
46 | 80 | ```
|
47 | 81 |
|
| 82 | +The expected result should be similar to: |
| 83 | + |
| 84 | +```bash |
| 85 | +START RequestId: e6e64a4e-b57d-11e6-9eee-0340b40f6d48 Version: $LATEST |
| 86 | +2016-11-28 16:18:23.755 (+01:00) e6e64a4e-b57d-11e6-9eee-0340b40f6d48 Your cron function "scheduled-cron-example-dev-cron" ran at Mon Nov 28 2016 15:18:23 GMT+0000 (UTC) |
| 87 | +END RequestId: e6e64a4e-b57d-11e6-9eee-0340b40f6d48 |
| 88 | +REPORT RequestId: e6e64a4e-b57d-11e6-9eee-0340b40f6d48 Duration: 4.01 ms Billed Duration: 100 ms Memory Size: 1024 MB Max Memory Used: 16 MB |
| 89 | + |
| 90 | +START RequestId: 0a770e6f-b57e-11e6-ba68-f188460981c7 Version: $LATEST |
| 91 | +2016-11-28 16:19:22.921 (+01:00) 0a770e6f-b57e-11e6-ba68-f188460981c7 Your cron function "scheduled-cron-example-dev-cron" ran at Mon Nov 28 2016 15:19:22 GMT+0000 (UTC) |
| 92 | +END RequestId: 0a770e6f-b57e-11e6-ba68-f188460981c7 |
| 93 | +REPORT RequestId: 0a770e6f-b57e-11e6-ba68-f188460981c7 Duration: 0.69 ms Billed Duration: 100 ms Memory Size: 1024 MB Max Memory Used: 16 MB |
| 94 | +``` |
| 95 | + |
| 96 | +Since this only shows you the logs of the first cron job simply change the function name and run the command again: |
| 97 | + |
| 98 | +```bash |
| 99 | +serverless logs --function secondCron --tail |
| 100 | +``` |
| 101 | + |
48 | 102 | ## Additonal Resources
|
49 | 103 |
|
50 |
| -For more information on running cron with Serverless check out the [Tutorial: Serverless Scheduled Tasks](https://parall.ax/blog/view/3202/tutorial-serverless-scheduled-tasks) by parallax. |
| 104 | +For more information on running cron with Serverless check out the [Tutorial: Serverless Scheduled Tasks](https://parall.ax/blog/view/3202/tutorial-serverless-scheduled-tasks) by parallax. |
0 commit comments