Aws-sam-cli: Missing !Sub and !If instrinsic functions

Created on 4 Jul 2018  路  10Comments  路  Source: aws/aws-sam-cli

Description:

Related to issue #490, please add support for !Sub !Ref, and a minimal !If implementation for environment vars in serverless function or in a globals section.

Not having this functionality means copy-paste duplication within a template, maintaining a duplicate template for local execution, copy-paste duplication to specify env vars on the command line, and/or the inability to override default values of environment variables via parameters at runtime.

Bonus points for supporting all variations expressing the fn in Yaml and Json

In 0.3.0 this was refactored and appears only to be supporter in a very limited context (e.g., swagger urls?).

Output of sam --version: 0.4.0

priorit1-critical stagin-progress stagin-review stagwaiting-for-release typregression

Most helpful comment

Now it's October 2020, sam cli version 1.6.2. Intrinsics like !Sub or !FindInMap don't work in sam local as far as I can see ('Unable to resolve property'). I can't find any other issue regarding this. Does that mean the plans to support this have been dropped?

All 10 comments

This is also related to #450 and #476.

Going to update labels.

@jfuss is there any progress on this?

It's a limiter for using layers as the ARN contains the region so can't have the template just load the correct layer by subbing the region. Managed to work around this so far but with layers I don't see a workaround.

@charsleysa exactly! I face the same problem with region and even layer versions (I want to use environment variables for those). Related: https://github.com/awslabs/serverless-application-model/issues/751

Just a heads up for those interested, !Ref has been implemented in #657.

I have (slowly) been working on some Sub support. I have pushed the code to my branch/repo. I have some functional tests that are working but missing:

  • Unit tests
  • A note/warning on not being able to resolve some Sub. This is really important since we cannot resolve commuted properties of resources.
  • Integ tests

If anyone is looking for a good way to contribute and need/want sub support, feel free to take what I started as the base.

Running into this also for Layers.

How do we get !Ref to work? I keep running into this:

Invalid value in Template for key: MY_ENV_VAR: expected string

Here is my template.yml:

Parameters:
  SomeTestParam:
    Type: String
    Default: foobar

...

SomeLambdaFunction:
    Type: AWS::Serverless::Function
    Properties:

      ...

      Environment:
        Variables:
          MY_ENV_VAR: !Ref SomeTestParam

I am on SAM CLI v0.19.0.

Also having trouble with !Sub not working with Layers

Release in v0.21.0.

Closing

Now it's October 2020, sam cli version 1.6.2. Intrinsics like !Sub or !FindInMap don't work in sam local as far as I can see ('Unable to resolve property'). I can't find any other issue regarding this. Does that mean the plans to support this have been dropped?

Was this page helpful?
0 / 5 - 0 ratings