2017-04-20 21 views
0

我想弄清楚如何以與標準AWS模板相同的方式自動生成JSON文件。如果您通過AWS工具包或在線設計器運行模板,則格式非常易讀。我在JSON編輯器中嘗試過的所有內容最終看起來都很糟糕,但我在網上看到大量json格式的模板,看起來完全像亞馬遜格式。我已經使用AWS工具試過,但只承認一個名爲「.template。是否有不同的插件文件,或者我應該輸入查詢?Eclipse:Autoformat JSON文件,如帶有Json編輯器插件的AWS Cloudformation模板

謝謝大家的自定義設置!

例(JSON) :

{ 
"AWSTemplateFormatVersion" : "2010-09-09", "Parameters" : { 
    "LogRetentionTime" : { 
     "Type" : "Number", "Default" : 90, "Description" : "Flow log retention time in days", "AllowedValues" : [ 1, 3, 5, 7, 14, 30, 60, 90, 120, 150, 180, 365, 400, 545, 731, 1827, 3653 ] 
    } 
}, "Resources" : { 
    "VpcFlowLog" : { 
     "Type" : "Custom::CreateVpcFlowLogs", "Properties" : { 
      "ServiceToken" : { 
       "Ref" : "CreateVpcFlowLogLambdaFunction" 
      }, "Region" : { 
       "Ref" : "AWS::Region" 
      }, "VpcId" : { 
       "Ref" : "Vpc" 
      }, "LogGroupName" : { 
       "Ref" : "VpcLogGroup" 
      }, "DeliverLogsPermissionArn" : { 
       "Fn::GetAtt" : [ "FlowLogsRole", "Arn" ] 
      } 
     }, "DependsOn" : [ ] 
    }, "FlowLogsRole" : { 
     "Type" : "AWS::IAM::Role", "Properties" : { 
      "AssumeRolePolicyDocument" : { 
       "Version" : "2012-10-17", "Statement" : [ { 
         "Effect" : "Allow", "Principal" : { 
          "Service" : "vpc-flow-logs.amazonaws.com" 
         }, "Action" : "sts:AssumeRole" 
        } ] 
      }, "Policies" : [ { 
        "PolicyName" : "root", "PolicyDocument" : { 
         "Version" : "2012-10-17", "Statement" : [ { 
           "Effect" : "Allow", "Action" : [ "logs:CreateLogGroup", "logs:CreateLogStream", "logs:PutLogEvents", "logs:DescribeLogGroups", "logs:DescribeLogStreams" ], "Resource" : "arn:aws:logs:*:*:*" 
          } ] 
        } 
       } ] 
     } 
    }, "VpcLogGroup" : { 
     "Type" : "AWS::Logs::LogGroup", "Properties" : { 
      "RetentionInDays" : { 
       "Ref" : "LogRetentionTime" 
      } 
     }, "DependsOn" : [ ] 
    } 
}, "Outputs" : { 
    "VpcFlowLog" : { 
     "Description" : "Flog log id", "Value" : { 
      "Fn::GetAtt" : [ "VpcFlowLog", "Id" ] 
     } 
    } 
} 

}

實施例(AWS):

{ 
"AWSTemplateFormatVersion": "2010-09-09", 
"Parameters": { 
    "LogRetentionTime": { 
     "Type": "Number", 
     "Default": 90, 
     "Description": "Flow log retention time in days", 
     "AllowedValues": [1,3, 5, 7, 14, 30, 60, 90, 120, 150, 180, 365, 400, 545, 731, 1827, 3653] 
    } 
}, 
"Resources": { 
    "VpcFlowLog": { 
     "Type": "Custom::CreateVpcFlowLogs", 
     "Properties": { 
      "ServiceToken": { "Ref" : "CreateVpcFlowLogLambdaFunction" }, 
      "Region": { "Ref": "AWS::Region" }, 
      "VpcId": { 
       "Ref": "Vpc" 
      }, 
      "LogGroupName": { 
       "Ref": "VpcLogGroup" 
      }, 
      "DeliverLogsPermissionArn": {"Fn::GetAtt" : ["FlowLogsRole", "Arn"] } 
     }, 
     "DependsOn": [] 
    }, 
    "FlowLogsRole": { 
     "Type": "AWS::IAM::Role", 
     "Properties": { 
      "AssumeRolePolicyDocument": { 
       "Version": "2012-10-17", 
       "Statement": [ 
        { 
         "Effect": "Allow", 
         "Principal": { 
          "Service": "vpc-flow-logs.amazonaws.com" 
         }, 
         "Action": "sts:AssumeRole" 
        } 
       ] 
      }, 
      "Policies": [ 
       { 
        "PolicyName": "root", 
        "PolicyDocument": { 
         "Version": "2012-10-17", 
         "Statement": [ 
          { 
           "Effect": "Allow", 
           "Action": [ 
            "logs:CreateLogGroup", 
            "logs:CreateLogStream", 
            "logs:PutLogEvents", 
            "logs:DescribeLogGroups", 
            "logs:DescribeLogStreams" 
           ], 
           "Resource": "arn:aws:logs:*:*:*" 
          } 
         ] 
        } 
       } 
      ] 
     } 
    }, 
    "VpcLogGroup": { 
     "Type": "AWS::Logs::LogGroup", 
     "Properties": { 
      "RetentionInDays": { "Ref" : "LogRetentionTime" } 
     }, 
     "DependsOn": [] 
    } 
}, 
"Outputs": { 
    "VpcFlowLog": { 
     "Description": "Flog log id", 
     "Value": { 
      "Fn::GetAtt": [ 
       "VpcFlowLog", 
       "Id" 
      ] 
     } 
    } 
} 

}

回答

0

如果您手動放置CRLF到文件末尾,Visual Studio將它們完美地格式化,它將bada激勵成完美的格式。