Wait for a function to be created before a resource


how can I wait for a function to be created before a resource is created?
the key “DependsOn” only works to wait for other resources and not the lambda created within the “function” key of the serverless.yml.
when i try to insert the name of lambda inside a DependsOn i reveive this error:

 Error --------------------------------------------------

  The CloudFormation template is invalid: Template format error: Unresolved resource dependencies [customResourceLambda] in the Resources block of the template

     For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.

  Stack Trace --------------------------------------------



I believe the problem is that you need to reference the lambda by the CF Normalized Name
Which would be something like: CustomResourceLambdaFunction

For more details, reference the Serverless Documentation


thanks for the answer.
i have already tried but not work yet.
this is my resource:

  DependsOn: "customResourceLambdaLambdaFunction" # i have try also without LambdaFunction 
  Type: "Custom::RateBasedRule"
        - ''
          - 'arn:aws:lambda:'
          - Ref: 'AWS::Region'
          - ':'
          - Ref: 'AWS::AccountId'
          - ':'
          - 'function:'
          - 'customResourceLambda'
    MetricName: predMaintHTTPFloodRule
    Name: predMaintHTTPFloodRule
    RateLimit: 2000
    RateKey: "IP"

my lambda function is not a resource but a function in a serverless.yml

- ${{file(./lambda/customResourceLambda.yml)}}
- ${{file(./resources/waf/rules/predMaintHTTPFloodRule.yml)}}

this is my situation.


I solved the problem, I went to see inside the stack file, inside the folder .serverless, in addition to adding LambdaFunction to the end of the name I had set, serverless also changes the first letter, from lowercase to uppercase, so now instead of putting customResourceLambdaLambdaFunction I put CustomResourceLambdaLambdaFunction and it works.