您可以在“ Fn :: Sub”中嵌套“ Fn :: FindInMap”吗?

时间:2019-11-22 01:39:07

标签: amazon-web-services amazon-cloudformation

我正在这样做:

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

但是我更喜欢像这样使用SUB,但是它不是有效的json:

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

1 个答案:

答案 0 :(得分:0)

您不能直接从Fn::FindInMap模板调用Fn::SubOnly a limited number of expressions work OOTB.

相反,您可以将其他变量传递给Fn::Sub。例如:

      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'

在这里,我计算一些值并将其作为EmptyVideoverarbeitungClusterAlarmFunction_Arn变量传递给Sub