# Reference to function in custom resources

**URL:** <https://forum.serverless.com/t/reference-to-function-in-custom-resources/539>\
**Category:** Serverless Framework\
**Created:** [October 14, 2016, 12:07pm UTC](https://forum.serverless.com/t/reference-to-function-in-custom-resources/539 "2016-10-14T12:07:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rkistner](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/rkistner/32/98_2.png) [@rkistner](https://forum.serverless.com/u/rkistner)\
**Post date:** [October 14, 2016, 12:07pm UTC](https://forum.serverless.com/t/reference-to-function-in-custom-resources/539/1 "2016-10-14T12:07:55Z")

</div>

Some custom resources may need to refer to Lambda functions. For example, defining an S3 bucket with events triggering lambda functions, or creating a user with access to a specific function.

It would typically be done with something like this:

```
Fn::GetAtt:
  - MyLambdaFunction
  - Arn

```

The problem is that with the initial deployment, the custom resources are created before the functions exist, and then this references an undefined function.

My current workaround is to first do an initial deployment without any custom resources, then do a second one with the custom resources. Once the functions have been deployed once, this works.

Are there any other suggestions for doing this?

---

<div class="post-metadata">

**Author:** ![flomotlik](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/flomotlik/32/3_2.png) [@flomotlik](https://forum.serverless.com/u/flomotlik)\
**Post date:** [October 14, 2016, 2:19pm UTC](https://forum.serverless.com/t/reference-to-function-in-custom-resources/539/2 "2016-10-14T14:19:53Z")

</div>

If that is still the case this is a bug. This should not be happening with 1.0.2 any more (it actually was fixed a while ago). Can you try this with the latest version and otherwise raise an issue in Github.

---

<div class="post-metadata">

**Author:** ![rkistner](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/rkistner/32/98_2.png) [@rkistner](https://forum.serverless.com/u/rkistner)\
**Post date:** [October 14, 2016, 2:36pm UTC](https://forum.serverless.com/t/reference-to-function-in-custom-resources/539/3 "2016-10-14T14:36:34Z")

</div>

This was with a recent master branch, commit 1411fb168 (after 1.0.2).

It seems like the custom resources are created in `cloudformation-template-create-stack.json`, while the lambda functions are only created in the next step in `cloudformation-template-update-stack.json`.

I’ll do some more testing and report an issue.

---

<div class="post-metadata">

**Author:** ![flomotlik](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/flomotlik/32/3_2.png) [@flomotlik](https://forum.serverless.com/u/flomotlik)\
**Post date:** [October 14, 2016, 3:09pm UTC](https://forum.serverless.com/t/reference-to-function-in-custom-resources/539/4 "2016-10-14T15:09:49Z")

</div>

Its probably related to this bug: [https://github.com/serverless/serverless/issues/2359](https://github.com/serverless/serverless/issues/2359)
