Is there a way I can pass a date or a cron schedule as an input to my state function - which is getting called by a cloud watch event? The cloud watch event runs on a cron schedule and I would like to pass that dynamically on a daily basis to the step function
For example:
This gives some static input, but I want to give each day's date as input
resource "aws_cloudwatch_event_target" "target" {
rule = aws_cloudwatch_event_rule.samplerule.id
arn = aws_sfn_state_machine.samplemachine.id
role_arn = aws_iam_role.iam_for_sfn.arn
input = <<EOF
{
"operand1": "3",
"operand2": "5",
"operator": "add"
}
EOF
}
The input to your Lambda function from a Scheduled Event looks something like this:
{
"id": "53dc4d37-cffa-4f76-80c9-8b7d4a4d2eaa",
"detail-type": "Scheduled Event",
"source": "aws.events",
"account": "123456789012",
"time": "2019-10-08T16:53:06Z",
"region": "us-east-1",
"resources": [ "arn:aws:events:us-east-1:123456789012:rule/MyScheduledRule" ],
"detail": {}
}
Using your choice of programming language, you can extract the time value and convert it from a string to a date resource/object (depending on your language). From that time, you can get the data components you are looking for.
IMPORTANT: All scheduled events use UTC time zone and the minimum precision for schedules is 1 minute: https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/ScheduledEvents.html
An alternative solution could be to use the global access to the context object , as explained here to get the execution start time of the step functions state machine.
So you can send it through your different states of your state machine like this:
"mystep1": {
"Type": "task",
"Parameters": {
"StartTime.$": "$$.Execution.StartTime"
}
...
}
Make sure to use the double $
to tell Cloudformation that you're using the global access to the context object.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.