Reference to function in custom resources

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?

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.

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.

Its probably related to this bug: https://github.com/serverless/serverless/issues/2359