I want to deploy function to AWS Lambda with using serverless framework in NodeJS/Typescript. Here is my serverless.yml:
service: backend
plugins:
- serverless-webpack
provider:
name: aws
region: eu-central-1
runtime: nodejs14.x
stage: dev
functions:
createDailyStatistics:
handler: dist/services/schedules.scheduleDailyStatistics
events:
- schedule:
rate: cron(0 0 * * *)
enabled: true
can someone tell me, why after launch serverless deploy i got an error like this:
CREATE_FAILED: CreateDailyStatisticsEventsRuleSchedule1 (AWS::Events::Rule)
Parameter ScheduleExpression is not valid. (Service: AmazonCloudWatchEvents; Status Code: 400; Error Code: ValidationException; Request ID: xxx; Proxy: null)
My expression - 0 0 * * * is a standard cron expression but AWS not handle this? I want to launch this functino on every day at midnight.
Thanks for any help!
AWS uses the extended CRON expression format:
Please notice, there are 6 fields in the expression: Minutes, Hours, Day of month, Month, Day of week and Year.
In your case, you provide only 5 values. I'm guessing you were most likely using crontab.guru to create your cron expression, meaning that you want an event to fire At 00:00. In that case, for AWS you would want to have something like this: 0 0 * * ? *.
Related
I want to trigger an Argo workflow to start running at a specific time. I am currently using a workflowTemplate and the rest API to submit a workflow with this template. Is there a way to tell Argo to start the workflow at a specific time.
I am aware of the existence of cron-workflow and cron-workflow-template. But I am not able to figure out how to use either workflow or cron-workflow to achieve what I want.
To have any scheduling, do I must use cron-workflow? Or is there a way to trigger a regular workflow at a delay by passing the schedule-time in submitOptions or in some other way through the rest API?
If I must use cron workflow, what should I set the schedule value at? I don't want it to run automatically or periodically, but only when I want and at a specific time. Is there a way achieve that using cronWorkflowTemplate and the rest API?
I will appreciate any help/pointers.
Likely not the answer you're looking for, but if you are able to alter your WorkflowTemplate, you can make the first step be an immediate suspend step, with a value that is provided as an input (by you, when deciding you want to submit the workflow, just not now). For instance, your workflow may look something like this:
apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
name: my-workflow-template
spec:
entrypoint: my-wf
arguments:
parameters:
- name: wait-time-sec
value: "0" # override me
templates:
- name: my-wf
inputs:
parameters:
- name: wait-time-sec
steps:
- - name: wait
template: wait-template
arguments:
parameters:
- name: wait-time-sec
value: "{{inputs.parameters.wait-time-sec}}"
- - name: rest of original workflow steps...
- name: wait-template
inputs:
parameters:
- name: wait-time-sec
suspend:
duration: "{{inputs.parameters.wait-time-sec}}"
...
When you want to submit it, just pass in the parameter wait-time-sec. Granted, if you would rather have a specific time, you would either have to calculate how many seconds that would be before submitting, or write a simple script before the wait step to do that calculation for you, taking in an input of a datetime and outputting seconds for the wait step to use.
I am trying to set a CloudWatch schedule event rule that will run on every quarter of year. But I am getting this error
"Parameter ScheduleExpression is not valid".
I tried following Cron expressions
cron(0 0 1 */3 * ?)
cron(0 0 1 */3 ? *)
But not working. Can anyone help in this?
Per AWS documentation
You cannot use * in both the Day-of-month and Day-of-week fields. If you use it in one, you must use ? in the other.
Also the year field does not support the ? wildcard, so your first expression is invalid.
The second one works:
aws events put-rule --schedule-expression "cron(0 0 1 */3 ? *)" --name so-test1
{
"RuleArn": "arn:aws:events:eu-west-1:3333:rule/so-test1"
}
Do you have a space after the closing bracket? That one marked as invalid for me
aws events put-rule --schedule-expression "cron(0 0 1 */3 ? *) " --name so-test1
An error occurred (ValidationException) when calling the PutRule operation: Parameter ScheduleExpression is not valid.
Say for example i want to run a job for a day at "3:22, 4:22, 6:22, 10:22, 18:22, 21.22" on these times just for the current day.
How could we write a cron expresion for it or using other Simple Trigger of Quartz API.
Using cron trigger you can set endAt() to stop trigger at the end of the day
trigger = newTrigger()
.withSchedule(cronSchedule(0 22 3,4,6,10,18,21 ? * * *))
.endAt(TRIGGER_END_TIME)
.forJob(myJobKey)
.build();
I have developed an time trigger azure function which is set to fired every hour but it is not triggering the function as expected. It's triggering behavior is very strange. I am attaching it's executing logs.
The cron expression for triggering the function is as follows:
0 0 * * * *
Anyone has any idea whats wrong with this?
The expression for hourly schedule is:
0 0 */1 * * *
https://learn.microsoft.com/en-us/azure/azure-functions/functions-create-scheduled-function#update-the-timer-schedule
Can you try below cron job expression,
https://www.freeformatter.com/cron-expression-generator-quartz.html#crongenerator
0 0 * ? * * *
But according to MS documents what you have used is correct. Are you using application insights ?
https://codehollow.com/2017/02/azure-functions-time-trigger-cron-cheat-sheet/
https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-timer
Below is an example cloud formation file in YAML format. The idea is to make the Route53 Record depend upon creation of the RDS Database and then once its created get the value from the endpoint of the RDS Database.
I did a lot of poking around in these reference documents but kept failing to get the syntax correct.
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-rds-database-instance.html#aws-properties-rds-database-instance-returnvalues
You can see it should have a return value but I'm not sure how to get it and use it for the route53 cName record name.
resources:
Resources:
uploadBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: ${self:custom.uploadBucket}
RDSDatabase:
Type: AWS::RDS::DBInstance
Properties:
Engine : mysql
MasterUsername: ${env:RDS_USERNAME}
MasterUserPassword: ${env:RDS_PASSWORD}
DBInstanceClass : db.t2.micro
AllocatedStorage: '5'
PubliclyAccessible: true
#TODO: The Value of Stage is also available as a TAG automatically which I may use to replace this manually being put here..
Tags:
-
Key: "Name"
Value: ${self:custom.databaseName}
DeletionPolicy: Snapshot
DNSRecordSet:
Type: AWS::Route53::RecordSet
Properties:
HostedZoneName: mydomain.com.
Name: database-${self:custom.stage}.mydomain.com
Type: CNAME
TTL: '300'
ResourceRecords:
- [[Put End Point Here]]
DependsOn: RDSDatabase
I tried doing this but no luck - ${!Ref RDSDatabase.Endpoint.Address}
An error occurred: DNSRecordSet - Invalid Resource Record: FATAL problem: RRDATANotSingleField (Value contains spaces) encounte
red with '${!Ref RDSDatabase.Endpoint.Address}'.
Found the answer its this...
ResourceRecords:
- {"Fn::GetAtt": ["RDSDatabase","Endpoint.Address"]}
I didn't know I could use the brackets like that in YAML...
Using the !GetAtt short form is even more readable.
ResourceRecords:
- !GetAtt RDSDatabase.Endpoint.Address
What I have done is, I have created an env variable to store the ref to the rds instance endpoint and used it as required
environment:
rdsEndpoint: !GetAtt <Name of the RDS instance>.Endpoint.Address
Now if i wanted to use it i can use it as
const endpoint = process.env.rdsEndpoint