boto3
boto3 copied to clipboard
Cannot update EventBridge event
Describe the bug
Fellows,
I'm trying to update an event in my EventBridge, but I'm constantly getting this error:
An error occurred (ValidationException) when calling the UpdateSchedule operation: scheduler is not a supported service for a target.
import json
import boto3
from datetime import datetime, timedelta
start_api = datetime.now() + timedelta(minutes=60)
scheduler_client = boto3.client('scheduler')
def lambda_handler(event, context):
scheduler_client.update_schedule(Name='MY_EVENT_NAME',
ScheduleExpression=f'cron({start_api.minute} {start_api.hour} {start_api.day} {start_api.month} ? {start_api.year})',
FlexibleTimeWindow={
'MaximumWindowInMinutes': 1,
'Mode': 'FLEXIBLE'
},
Target={
'Arn': 'arn:aws:scheduler:MY_ARN',
'RoleArn': 'arn:aws:iam::MY_ROLE_ARN'
}
)
return {
'statusCode': 200,
'body': json.dumps('Working!')
}
I even provided the admin role permissions to my Role and don't know why I'm getting this error. Any idea what am I doing wrong?
Expected Behavior
It should update the event.
Current Behavior
It's giving this error:
An error occurred (ValidationException) when calling the UpdateSchedule operation: scheduler is not a supported service for a target.
Reproduction Steps
- Create a Lambda Function.
- Download
Boto3to your PC:pip install boto3 -t ./python. - Create a zip:
zip -r layer.zip ./python - Import
Boto3as a layer. - Copy and paste the following code:
import json
import boto3
from datetime import datetime, timedelta
start_api = datetime.now() + timedelta(minutes=60)
scheduler_client = boto3.client('scheduler')
def lambda_handler(event, context):
scheduler_client.update_schedule(Name='MY_EVENT_NAME',
ScheduleExpression=f'cron({start_api.minute} {start_api.hour} {start_api.day} {start_api.month} ? {start_api.year})',
FlexibleTimeWindow={
'MaximumWindowInMinutes': 1,
'Mode': 'FLEXIBLE'
},
Target={
'Arn': 'arn:aws:scheduler:MY_ARN',
'RoleArn': 'arn:aws:iam::MY_ROLE_ARN'
}
)
return {
'statusCode': 200,
'body': json.dumps('Working!')
}
- Give permission to the Lambda function to modify the EventBridge.
- Create a new test event.
- Run it.
Possible Solution
No response
Additional Information/Context
No response
SDK version used
1.26.50
Environment details (OS name and version, etc.)
AWS, Lambda
Hi @FANMixco - thanks for reaching out and sorry to hear about the issue.
I attempted to replicate the issue with the simple code snippet below and wasn't able reproduce the same behavior. According to API docs, the error you're getting indicates that "The input fails to satisfy the constraints specified by an AWS service.".
After deep dive and looking at your code, I suspect the issue might be with ScheduleExpression expression. Have you tried other expressions besides cron format?
Here's more on the schedule types and expressions for your reference: https://docs.aws.amazon.com/scheduler/latest/UserGuide/schedule-types.html
If the issue persists, please share debug logs without any sensitive information by adding boto3.set_stream_logger('') to your script. That would give us more insights on locating the issue.
Thanks
John
client = boto3.client('scheduler')
response = client.update_schedule(
FlexibleTimeWindow={
'MaximumWindowInMinutes': 123,
'Mode': 'FLEXIBLE'
},
Name='string',
ScheduleExpression='cron({start_api.minute} {start_api.hour} {start_api.day} {start_api.month} ? {start_api.year})',
State='ENABLED',
Target={
'Arn': 'string',
'RoleArn': 'string',
}
)
print(response)
Hi @FANMixco - thanks for reaching out and sorry to hear about the issue.
I attempted to replicate the issue with the simple code snippet below and wasn't able reproduce the same behavior. According to API docs, the error you're getting indicates that "The input fails to satisfy the constraints specified by an AWS service.".
After deep dive and looking at your code, I suspect the issue might be with
ScheduleExpressionexpression. Have you tried other expressions besidescronformat?Here's more on the schedule types and expressions for your reference: https://docs.aws.amazon.com/scheduler/latest/UserGuide/schedule-types.html
If the issue persists, please share debug logs without any sensitive information by adding
boto3.set_stream_logger('')to your script. That would give us more insights on locating the issue. Thanks Johnclient = boto3.client('scheduler') response = client.update_schedule( FlexibleTimeWindow={ 'MaximumWindowInMinutes': 123, 'Mode': 'FLEXIBLE' }, Name='string', ScheduleExpression='cron({start_api.minute} {start_api.hour} {start_api.day} {start_api.month} ? {start_api.year})', State='ENABLED', Target={ 'Arn': 'string', 'RoleArn': 'string', } ) print(response)
Hi @aBurmeseDev, after a call with the AWS support team, we concluded a couple of things:
-
- Lambda functions in Python 3.9 on Jan 16, 2023 are using a very old Boto version, 1.20.32.
-
- You're forced to create a layer on your own and upload the latest version.
-
- The tricky values come from here:


I even wrote a tutorial since there are not many examples:
https://dev.to/fanmixco/how-to-update-eventbridge-schedules-with-lambdas-2482
What's more, I suggested to them that there are some values that should be taken by default if you don't provide anything:
- Target => Why should I update each time what I'm rescheduling?
- FlexibleTimeWindow => Why should I change it if I pre-created one with certain conditions?
These values make sense to be mandatory when you're creating a schedule, not when you're updating one.