How to create a basic EventBridge in Serverless

Hi, I am trying to create a Simple AWS EventBridge on a Lambda Function, both of which are being created using Serverless Script.

Here is the code I am trying to use in serverless.yml (Some variables are unset) also handler.js is default

service: event-bridge-cloudformation

provider:
  name: aws
  runtime: nodejs10.x
  region: us-east-1

functions:
  hello:
    handler: handler.hello

resources:
 Resources:
    ScheduledRule: 
      Type: AWS::Events::Rule
      Properties: 
        Description: "ScheduledRule"
        ScheduleExpression: "rate(1 minutes)"
        State: "ENABLED"
        Targets: 
          - 
            Arn: 
              Fn::GetAtt: 
                - "arn:aws:lambda:${self:provider.region}:${self:provider.environment.AWS_ACCOUNT}:function:${self:service}-${self:provider.stage}-hello"
                - "Arn"

Above code is giving me following error:
Error: The CloudFormation template is invalid: Template error: instance of Fn::GetAtt references undefined resource

Can you please help me with some basic template in serverless that creates both lambda and an EventBridge on that Lambda

Thanks.

Looks like you’re trying to get an Arn from an Arn. That is, you’re constructing the arn as a string, then trying to get the arn from that string. Here’s 2 potential solutions to your issue:

  1. Construct the Arn as a string:
Targets:
  - 
    Arn: "arn:aws:lambda:${self:provider.region}:${self:provider.environment.AWS_ACCOUNT}:function:${self:service}-${self:provider.stage}-hello"
  1. Get the Arn from the LogicalId of the Hello Function
Targets:
  - 
    Arn:
        Fn::GetAtt: 
          - "HelloLambdaFunction"
          - "Arn"

Hope it helps.

1 Like

Thanks Brett, it helped :slight_smile:

1 Like