0

I'm new to AWS and SAM, so this may be an obvious question, but I just can't find an answer to it. I'm trying to construct a SAM template that allows the user to inject a parameter that will affect the names of all resources within. Specifically, an "environment" parameter can be passed in, which will then be used to qualify all resource names:

AWSTemplateFormatVersion: "2010-09-09"
Transform: "AWS::Serverless-2016-10-31"
Parameters:
  EnvironmentParameter:
    Type: "String"
    Default: "default"
Resources:
  GetTermsAndConditionsFunction:
    Type: "AWS::Serverless::Function"
    Properties:
      # TODO: prepend the environment somehow so I get "$ENVIRONMENT_MyFunction" instead
      FunctionName: "MyFunction"
      Handler: "..."
      ...

How can I dynamically construct a FunctionName using EnvironmentParameter?

me--
  • 1,978
  • 1
  • 22
  • 42

1 Answers1

5

All the Cloudformation functions work in SAM templates as well. So you would use the Fn::Sub function to replace the EnvironmentParameter in your FunctionName

FunctionName: !Sub "${EnvironmentParameter}_MyFunction"

Link for more details on Fn::Sub function.

Hope this helps!

Nune Isabekyan
  • 531
  • 2
  • 4