-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When using !Sub or !Ref in the 'Enabled' property in when 'Schedule' of AWS::Serverless::Function. #1943
Comments
These code could be the problematic part. |
Add a workaround:Since the issue is not successfully transforming the template with the intrinsic function we have workaround: Using Please check the below SAM template samples: Transform: AWS::Serverless-2016-10-31
Parameters:
S3Bucket:
Type: String
TriggerState:
Type: String
Default: false
AllowedValues:
- true
- false
Resources:
ExampleLambda:
Type: AWS::Serverless::Function
Properties:
FunctionName: example
Handler: example
Runtime: python3.8
CodeUri:
Bucket: <MyBucket>
Key: Lambda.py.zip
Events:
LambdaSchedule:
Fn::Transform :
Name : AWS::Include
Parameters :
Location :
Fn::Sub: "s3://${S3Bucket}/${TriggerState}.yml" --- true.yml --- Type: Schedule
Properties:
Name: lambda-trigger
Schedule: cron(0 4 * * ? *)
Description: description
Enabled: true --- false.yml --- Type: Schedule
Properties:
Name: lambda-trigger
Schedule: cron(0 4 * * ? *)
Description: description
Enabled: false |
I can reproduce this issue on v1.19.1 (via github actions) Another workaround is to conditionally set the cron job to run on a past date like so: Type: Schedule
Properties:
Name: lambda-trigger
# Workaround for disabling schedule
Schedule: !If
- TriggerState # Condition
- cron(0 1 * * ? *) # 1:00 AM UTC or a custom schedule here
- cron(0 1 1 1 ? 1970) # Never run
Description: description
Enabled: True |
Just ran into this issue, more than a year later. Still happening in version 1.46.0. |
You might be able to get this to work by adding Transform:
- AWS::LanguageExtensions
- AWS::Serverless-2016-10-31
See #2533 for more information. |
Closing in favor of #2533. |
Description:
!Sub or !Ref in the 'Enabled' property in when 'Schedule' of AWS::Serverless::Function, it cannot be transformed correctly. The AWS::CloudWatch::Rule will always use 'ENABLED' for State property
Steps to reproduce:
Launch the template below:
Observed result:
After the template is transformed/launched with 'false' to 'TriggerState', the property State of AWS::CloudWatch::Rule will be 'ENABLED'
Expected result:
As I passed 'false' for Enabled, the AWS::CloudWatch::Rule property State should be disabled.
Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
sam --version
: SAM CLI, version 1.15.0Add --debug flag to any SAM CLI commands you are running
The text was updated successfully, but these errors were encountered: