question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Conditionals, Refs, etc. in template yaml don't appear to be evaluated

See original GitHub issue

I expected the conditional here to produce “some value” when run with sam local and the EnvType parameter unset or set to “test”. Instead it produced no value. My function sees the environment variable “TABLE” as holding an empty string.

There’s an error in the output of sam local start-api when using this template: ERROR: json: cannot unmarshal array into Go struct field AWSServerlessFunction_FunctionEnvironment.Variables of type string. Converting the array style !Equals and !If to their Equals: and If: equivalents merely changes the error to ‘cannot unmarshal object into…’

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:15 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
JasonHenriksencommented, Apr 15, 2019

@jfuss So specifically, I wanted to use SAM to allocate a bucket, and pass the name of the bucket as needed by the aws-sdk into a node lambda. I was only testing locally and I tried every possible example to do that I could find to do that. I spent literally hours trying to do this, and I didn’t bother to try it on the cloud, because my thinking was “if it doesn’t work locally what’s the point of trying it on the server.”

Really, the promise of local testing is that it does replicate what cloudformation does on a local box. Especially for brand new users like me who are just learning this stuff. I have zero experience with cloudformation. I am starting out brand new with SAM, and from my perspective, every single example of how to pass template variables around just mysteriously does not work.

So here are my asks:

  1. Replicate what cloudformation does with those names. It’s a big lift and I understand if you can’t do it. But if you can’t do this one you MUST do the next one

  2. PROVIDE A REAL ERROR MESSAGE! If you know that an intrinsic function will work in the cloud, but not work locally, then you must provide a local implementation of the call that writes to the console saying, “We’re sorry. That function will work on the cloud, but will not work on local environments”. That one error message would have saved me hours and hours of time and would explain to new users what is going on. I could have googled for that error message to find our about the lack of intrinsic function support. As it is, the call the the function fails in complete silence and I have no idea why the examples don’t work.

The idea of local run is a huge win when it works. I am thankful to your team for putting in the time and effort. However, SAM and CloudFormation are your API. If there are parts of that API that you are leaving unimplemented, you really really need to provide an error message saying so.

Thanks again for all your work and your response to my message.

  • Jason
4reactions
bedgecommented, Jun 8, 2018

@sanathkr Here’s a case you need conditionals for.

I need to deploy a lambda fn to 2 different AWS accounts. In one, I need to specify a VpcConfig, in the other, I don’t/can’t.

Simply replacing the values with empty strings in the latter case won’t work. The entire block needs to be removed:

VpcConfig:
  SecurityGroupIds:
    - stagevpc-xx
  SubnetIds:
    - mgmtsubnet-us-east-1a
Read more comments on GitHub >

github_iconTop Results From Across the Web

Conditionals, Refs, etc. in template yaml don't appear ... - GitHub
I expected the conditional here to produce "some value" when run with sam ... Conditionals, Refs, etc. in template yaml don't appear to...
Read more >
CloudFormation Mapping and Conditionals - SingleStone
A guide on cloudformation mapping and conditionals: develop templates that can be used to create “stacks” of resources in AWS that are ...
Read more >
Condition functions - AWS CloudFormation
These conditions are evaluated based on input parameters that you declare when you create or update a stack. After you define all your...
Read more >
how can I use IF ELSE in variables of azure DevOps yaml ...
I found 1 reference from the following one, but this one seems to work if the variables section doesn't have variable groups. https:// ......
Read more >
Templates | OpenShift Container Platform 3.11
If you have a JSON or YAML file that defines a template, for example as ... A parameter reference may appear in any...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found