Skip to content
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

Fn::If in AWS::Serverless::Function-Events #2342

Closed
farski opened this issue Aug 30, 2022 · 2 comments
Closed

Fn::If in AWS::Serverless::Function-Events #2342

farski opened this issue Aug 30, 2022 · 2 comments

Comments

@farski
Copy link

farski commented Aug 30, 2022

cfn-lint version: 0.63.0

Description of issue.

I'm seeing a couple weird behaviors with Fn:If in the Events property of AWS::Serverless::Function.

When I do the following, I get a warning that IsPrimaryRegion is never used.

Conditions:
  IsPrimaryRegion: !Equals [!Ref RegionMode, Primary]

Resources:
  MyFunction:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri:
        Bucket: !Ref CodeS3Bucket
        Key: !Ref CodeS3ObjectKey
      Events:
        ScheduleTrigger:
          Properties:
            Schedule: !Sub rate(${kScheduleIntervalMinutes} ${kScheduleIntervalLabel})
            Enabled: !If [IsPrimaryRegion, true, false]
          Type: Schedule

If I change to putting the entire event in an If:

Conditions:
  IsPrimaryRegion: !Equals [!Ref RegionMode, Primary]

Resources:
  MyFunction:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri:
        Bucket: !Ref CodeS3Bucket
        Key: !Ref CodeS3ObjectKey
      Events:
        ScheduleTrigger: !If
          - IsPrimaryRegion
          - Properties:
              Schedule: !Sub rate(${kScheduleIntervalMinutes} ${kScheduleIntervalLabel})
              Enabled: true
            Type: Schedule
          - !Ref AWS::NoValue

It complains that ScheduleTrigger has no ID. (There are other Events, so that property is never empty).

@chrisoverzero
Copy link
Contributor

cfn-lint is correct here: The Enabled property in SAM Schedule configuration doesn't work the way it seems like it should. I've addressed this before, but the short answer is that Enabled can't accept an intrinsic – like !If – it gets transformed to a constant ENABLED.

The SAM team has added State, which is passed through directly in the CloudFormation transformation, but I think it hasn't been released yet. SAM 1.50.0 was released 22 days ago, and that MR was merged 21 days ago. So close!

@farski
Copy link
Author

farski commented Sep 8, 2022

@chrisoverzero Ah, that's an interesting gotcha. Good to know about the forthcoming State. Thanks.

@farski farski closed this as completed Sep 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants