Referring to function resource from custom resources


I see that Serverless appends LambdaFunction to the names of function resources when it creates the Cloudformation template. When I refer to these functions in the custom resources section of my serverless.yml I have been doing the same:

  sendEmail: # I want to refer to this resource later
      Type: AWS::Events::Rule
          - Arn:
                - sendEmailLambdaFunction # I have to append `LambdaFunction` to the name specified under `functions`
                - Arn
      Type: AWS::Lambda::Permission
          Ref: sendEmailLambdaFunction # I have to append `LambdaFunction` to the name specified under `functions`

Is there a better way to do this, that doesn’t require implicit knowledge about how Serverless compiles the yaml file?

Update: I see in the documentation that this is a standard pattern, so presumably it will always be safe to hard-code the function name with LambdaFunction appended. I would still be interested to know whether there is another way to get the same string, such as through a variable.


You’re doing it the right way.

The only improvement to this system (i.e. having a standardised naming convention) would be to add helper functions (probably as part of the variables system?) to convert serverless.yml references to CFN Logical IDs, but I doubt it’s worth the extra complexity at this stage.


Note to future readers that if your function name key contains ‘-’, you would have to replace them by Dash.

For instance: hello-world -> HelloDashworldLambdaFunction`. (note the leading capitalized letter)