# SLS CloudFormation Resource Depends on SLS Lambda Function Issue

**URL:** <https://forum.serverless.com/t/sls-cloudformation-resource-depends-on-sls-lambda-function-issue/8857>\
**Category:** Serverless Framework\
**Tags:** aws, lambda, cloudformation\
**Created:** [July 22, 2019, 5:26pm UTC](https://forum.serverless.com/t/sls-cloudformation-resource-depends-on-sls-lambda-function-issue/8857 "2019-07-22T17:26:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![wenindoubt](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/wenindoubt/32/3410_2.png) [@wenindoubt](https://forum.serverless.com/u/wenindoubt)\
**Post date:** [July 22, 2019, 5:26pm UTC](https://forum.serverless.com/t/sls-cloudformation-resource-depends-on-sls-lambda-function-issue/8857/1 "2019-07-22T17:26:34Z")

</div>

I am providing Cognito the permission to invoke lambda functions via lambda triggers ([https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-identity-pools-working-with-aws-lambda-triggers.html](https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-identity-pools-working-with-aws-lambda-triggers.html))

I have a very basic resource created in `serverless.yml`:

```auto
    UserPoolLambdaInvokePermission:
      Type: AWS::Lambda::Permission
      Properties:
        Action: lambda:invokeFunction
        Principal: cognito-idp.amazonaws.com
        FunctionName: arn:aws:lambda:${self:provider.region}:#{AWS::AccountId}:function:${self:service}-${self:provider.stage}-cognitoCustomMessage
        SourceArn: arn:aws:cognito-idp:${self:provider.region}:#{AWS::AccountId}:userpool/${self:provider.environment.USER_POOL_ID}

```

The above allows Cognito to invoke my `cognitoCustomMessage` lambda:

```auto
cognitoCustomMessage:
  handler: src/main/lambdas/users_handler.cognitoCustomMessage

```

The error message I am receiving above is: `An error occurred: CognitoCustomMessageLambdaFunction - Function not found: arn:aws:lambda:us-west-2:1234567890:my-service-dev-cognitoCustomMessage (Service: AWSLambdaInternal; Status Code: 404; Error Code: ResourceNotFoundException; Request ID: e2a98525-5090-4d0f-a1f5-20610474f93b).`

If I insert a `DependsOn` into the above resource like so:

```auto
    UserPoolLambdaInvokePermission:
      Type: AWS::Lambda::Permission
      DependsOn: arn:aws:lambda:${self:provider.region}:#{AWS::AccountId}:function:${self:service}-${self:provider.stage}-cognitoCustomMessage
      Properties:
        Action: lambda:invokeFunction
        Principal: cognito-idp.amazonaws.com
        FunctionName: arn:aws:lambda:${self:provider.region}:#{AWS::AccountId}:function:${self:service}-${self:provider.stage}-cognitoCustomMessage
        SourceArn: arn:aws:cognito-idp:${self:provider.region}:#{AWS::AccountId}:userpool/${self:provider.environment.USER_POOL_ID}

```

The error message I am receiving from above is: `The CloudFormation template is invalid: Template format error: DependsOn must be a string or list of strings.`

If I hardcode (which I don’t want to) the entire ARN of the lambda function, I get the following error: `The CloudFormation template is invalid: Template format error: Unresolved resource dependencies [arn:aws:lambda:us-west-2:1234567890:function:my-service-dev-cognitoCustomMessage] in the Resources block of the template`

Has anyone else run into a similar error or figured out an elegant workaround?

---

<div class="post-metadata">

**Author:** ![ionush](https://avatars.discourse-cdn.com/v4/letter/i/85e7bf/32.png) [@ionush](https://forum.serverless.com/u/ionush)\
**Post date:** [February 27, 2020, 3:15am UTC](https://forum.serverless.com/t/sls-cloudformation-resource-depends-on-sls-lambda-function-issue/8857/2 "2020-02-27T03:15:23Z")

</div>

found the solution, use dependOn property and get the function name from .serverless/serverless-state.json
