red888
red888

Reputation: 31610

Can you nest "Fn::FindInMap" inside "Fn::Sub"?

I'm doing this:

{"Fn::Join": [":", [
    "arn:aws:sns",
    { "Ref": "AWS::Region"},
    { "Ref": "AWS::AccountId"},
    {"Fn::FindInMap" : [ "config", "mytopic", { "Ref" : "deployment" } ] }
]]

But I would prefer to use SUB like this but it's not valid JSON:

{"Fn::Sub" : "arn:aws:sns:${AWS::Region}:${AWS::AccountId}:${"Fn::FindInMap" : [ "config", "mytopic", { "Ref" : "deployment" } ] }"}

Upvotes: 2

Views: 1014

Answers (1)

lexicore
lexicore

Reputation: 43691

You can't call Fn::FindInMap directly from the Fn::Sub template. Only a limited number of expressions work OOTB.

Instead you can pass additional variables to Fn::Sub. For example:

      DefinitionString: !Sub 
        - |-
          {
             "Comment":"Extract metadata and anonymize the videoclip",
             "StartAt":"ExtractMetadataAndAnonymize",
             "States":{
                "ExtractMetadataAndAnonymize":{
                   "Type":"Parallel",
                   "Next":"LogResult",
                   "Branches":[
                      {
                         "StartAt":"AlarmIfVideoverarbeitungClusterIsEmpty",
                         "States":{
                            "AlarmIfVideoverarbeitungClusterIsEmpty":{
                               "Type":"Task",
                               "Resource":"${EmptyVideoverarbeitungClusterAlarmFunction_Arn}",
                               ....
                }
             }
          }
        - EmptyVideoverarbeitungClusterAlarmFunction_Arn: !ImportValue 
            'Fn::Sub': 'stk-${EnvType}-${EnvId}-videoverarbeitung-cluster-EmptyVideoverarbeitungClusterAlarmFunction-Arn'

Here, I calculate some value and pass it as EmptyVideoverarbeitungClusterAlarmFunction_Arn variable to Sub.

Upvotes: 1

Related Questions