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

EventBridgeRule breaks with Fn::Sub: "Name not defined for resource of type EventBridgeRule" #3260

Closed
garretwilson opened this issue Jul 17, 2023 · 6 comments
Assignees
Labels
stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. type/docs

Comments

@garretwilson
Copy link

garretwilson commented Jul 17, 2023

I had a very straightforward CloudFormation template, containing a Lambda that listened to EventBridge events with the detail type "FooBar". It looked like this

  MyEventBus:
    Type: AWS::Events::EventBus
    Properties:
      Name: my-event-bus

  MyFunction:
    Type: AWS::Lambda::Function



  MyEventRule:
    Type: AWS::Events::Rule
    Properties:
      Name: !Sub "${AWS::StackName}-my-rule"
      EventBusName: !Ref MyEventBus
      EventPattern:
        detail-type: ["FooBar"]
      Targets:
        - Id: !Ref MyFunction
          Arn: !GetAtt MyFunction.Arn

"Use SAM," they said. "SAM will make things easier." So I converted it to SAM. I put the magic stuff at the top:

AWSTemplateFormatVersion: 2010-09-09
Transform:
  - AWS::LanguageExtensions
  - AWS::Serverless-2016-10-31

Then I "simplified" the function definition (except for the CodeUri stuff, which I had to turn into a kludge to work around #3264):

  MyFunction:
    Type: AWS::Serverless::Function
    Properties:
      
      Events:
        Trigger:
          Type: EventBridgeRule
          Properties:
            Name: !Sub "${AWS::StackName}-my-rule"
            EventBusName: !Ref MyEventBus
            Pattern:
              detail-type: ["FooBar"]
            Target:
              Id: !Ref MyFUnction

We are truly far from rocket science at this point. But SAM doesn't like that. I do a sam deploy and get this:

Error: Failed to create changeset for the stack: my-stack, ex: Waiter ChangeSetCreateComplete failed: Waiter encountered a terminal failure state: For expression "Status" we matched expected path: "FAILED" Status: FAILED. Reason: Transform AWS::Serverless-2016-10-31 failed with: Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MyFunctionTrigger] is invalid. property Name not defined for resource of type EventBridgeRule

Please tell me this is not (again!) what I think it is. Please tell me I am making some mistake and I have screwed up the conversion. Please tell me I'm being slow this morning and have made a typo or something. Please tell me this is not SAM again making things "simple" for me and wasting my day to file bugs.

Please, I want the mistake to be mine. I would welcome it.

@garretwilson garretwilson added the stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. label Jul 17, 2023
@garretwilson garretwilson changed the title Name not defined for resource of type EventBridgeRule EventBridgeRule breaks with Fn::Sub: "Name not defined for resource of type EventBridgeRule" Jul 17, 2023
@garretwilson
Copy link
Author

Please, I want the mistake to be mine. I would welcome it.

It appears unfortunately that I made no mistake and this is yet again SAM getting horribly confused when I try to do anything interesting—that is, anything in real life that doesn't appear as an example in a tutorial.

I commented out the Name:

  MyFunction:
    Type: AWS::Lambda::Function
    Properties:
      
      Events:
        Trigger:
          Type: EventBridgeRule
          Properties:
            #TODO bring back when https://github.com/aws/serverless-application-model/issues/3260 is fixed: Name: !Sub "${AWS::StackName}-my-rule"
            EventBusName: !Ref MyEventBus
            Pattern:
              detail-type: ["FooBar"]
            Target:
              Id: !Ref MyFUnction

(Funny, my SAM template is becoming full such lines: "bring back when bug XXX is fixed".)

And that allowed it to deploy.

Unfortunately, it looks like SAM won't let me use a simple Fn::Sub in the name of an EventBridgeRule—something that is like a 1.5 on a scale of 1–10 for "complexity".

People, seriously. I mean this is every day. I haven't even tried to do anything complicated with SAM yet!

I want to be a team player. Why don't you hire me and let me help you fix all these problems? I'm serious. Completely serious. Bring me on board. I'll work with you to make it work. And not just work, but make it solid.

@hawflau
Copy link
Contributor

hawflau commented Jul 17, 2023

Thanks for raising the issue. This seems to be SAM Transform issue. Transferring.

@hawflau hawflau transferred this issue from aws/aws-sam-cli Jul 17, 2023
@ssenchenko
Copy link
Contributor

It seems like you wanted to use AWS::Serverless::Function. AWS::Lambda::Function doesn't have all those extensions. So once you change the type, I suppose everything will work.

@garretwilson
Copy link
Author

garretwilson commented Jul 17, 2023

It seems like you wanted to use AWS::Serverless::Function. AWS::Lambda::Function doesn't have all those extensions.

That was a typo. I have now corrected the bug description.

So once you change the type, I suppose everything will work.

I suppose you haven't tested it.

@aaythapa
Copy link
Contributor

Hi @garretwilson thanks for reporting this issue. Turns out it was an error in our docs. The property is called RuleName not Name and thats what was causing your deployment to fail. Sorry about this.

I tested with the following template and it deployed fine.

AWSTemplateFormatVersion: 2010-09-09
Transform:
  - AWS::LanguageExtensions
  - AWS::Serverless-2016-10-31
Resources:
  
  MyEventBus:
    Type: AWS::Events::EventBus
    Properties:
      Name: my-event-bus

  MyLambdaFunction:
    Type: AWS::Serverless::Function
    Properties:
      Handler: index.handler
      Runtime: nodejs14.x
      InlineCode: ...
      Events:
        Trigger:
          Type: EventBridgeRule
          Properties:
            RuleName: !Sub "${AWS::StackName}-my-rule"
            EventBusName: !Ref MyEventBus
            Pattern:
              detail-type: ["FooBar"]

We'll be updating the docs asap. Let us know if this fixes your error or if it persists. Thanks again.

@aaythapa
Copy link
Contributor

Doc change merged, should be rolling out soon. Closing this ticket for now, please re-open if needed.

@aaythapa aaythapa self-assigned this Jul 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. type/docs
Projects
None yet
Development

No branches or pull requests

4 participants