Home > Net >  Is is possible to use !Sub to concatinate one environment variable with another in SAM CLI templates
Is is possible to use !Sub to concatinate one environment variable with another in SAM CLI templates

Time:11-21

I have a group of lambdas that I have most of the items within parameter store parameters. I have the sub trees seperated by envrionment.

Example

/prod/type/app1/parameter1
/prod/type/app1/parameter2
/prod/type/app2/parameter1
/dev/type/app1/parameter1
/dev/type/app1/parameter2
/dev/type/app2/parameter1

I would like to reference the path within the environment variables of a template.yml for a lambda function using SAM CLI.

I am trying to use !Sub but I am not having the results that I was hoping for.

Example:

Environment:
  Variables:
    ENV: "DEV"
    SSM_PS_APP1_PATH: !Sub "/${ENV}/type/app1/"

The Results I get are:

/ENV/type/app1

My question is it possible to reference another variable within the Environment Variable Declaration using !Sub?

CodePudding user response:

Sadly, its not possible. You would have to make ENV CloudFormation variable as well:

Parameters:
  ENV:
   Default: DEV

and then:

Environment:
  Variables:
    ENV: !Ref ENV
    SSM_PS_APP1_PATH: !Sub "/${ENV}/type/app1/"
  • Related