aws-sam-cli: Conditionals, Refs, etc. in template yaml don't appear to be evaluated

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…’

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 3
  • Comments: 15 (3 by maintainers)

Most upvoted comments

@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

@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

Should this caveat be mentioned in the documentation? It took a lot of searching to hunt down this closed Git issue. Maybe mention under Project Status or a new section on limitations/caveats?

https://github.com/awslabs/aws-sam-local/#project-status

@jfuss, guess who ran into this almost five years after this issue was created. This guy!

It might be useful to put a note about testing locally with SAM somewhere in the documentation.

And there are no plans to support any intrinsic functions in the future?