6

Using AWS Cloudformation, my aws cloudformation create-stack fails for some yet-unclear reason. For this question the error and the explanation aren't relevant, but I think I'm passing a parameter with --parameters that's not correctly handled within the CloudFormation template, or there might be an error in evaluating expressions or referencing variables in the template.

Anyway, I really would like to be able to output some debug statements or expressions during evaluation of the template; the provisioning of the stack. What's the CloudFormation equivalent of logging.debug(some-expression) that gets the expression output to CloudWatch Logs or some other output channel?

The Events log in the CloudFormation Stacks shows the error (in my case), but unfortunately not the details that I need to fix the bug. It doesn't show the value of variables or CloudFormation expressions during execution / provisioning, and (by my knowledge) I can't create events that'll show the values of variables or expressions. CloudWatch Logs is empty, with respect to provisioning tasks. And aws cloudformation validate-template reveals no errors, so the CloudFormation template is syntactically correct.

Jochem Schulenklopper
  • 6,452
  • 4
  • 44
  • 62
  • 1
    Maybe a custom resource that your logging message as a parameter and then sends it somewhere? Can even just print it so it's available in CloudWatch. – kichik May 11 '20 at 16:37
  • OK, but using a custom resource to collect an expression's value, and then including that resource in the template's output is... quite a detour :-D – Jochem Schulenklopper May 11 '20 at 18:55

1 Answers1

2

What's the CloudFormation equivalent of logging.debug(some-expression) that gets the expression output to CloudWatch Logs or some other output channel?

Unfortunately, there is no such functionality provided by AWS. The only tool provided by AWS is aws cloudformation validate-template. General information on how to use template validation is described in a recent AWS blog:

However, some sort of debugging comes from creating a change set, but this only applies when you update existing stack.

You can also find some third party tools, such as yaml checkers or CloudFormation template linters, for checking your templates. Many of these tools are listed in this SO question.

Ultimately, to be sure your template will work you have to attempt to deploy it.

Marcin
  • 215,873
  • 14
  • 235
  • 294
  • Thanks. I did a `validate-template` but that's mainly a syntactic check (and not a log of things during execution). I also found that other StackOverflow question and the references therein, but missed a tool about dynamic output messages during provisioning. – Jochem Schulenklopper May 11 '20 at 07:49
  • 3
    "Ultimately, to be sure your template will work you have to attempt to deploy it." Yeah, which is what I'm doing. It's like debugging in production, but not having the capability to log output statements during execution :-) – Jochem Schulenklopper May 11 '20 at 07:50
  • 1
    @JochemSchulenklopper I know your pain. The tip is to keep your templates small. Its much easier to figure out what's happening if a template contains one or two resources only. – Marcin May 11 '20 at 07:51