Eclipse:Autoformat JSON文件,如带有Json编辑器插件的AWS Cloudformation Template

时间:2017-04-20 12:48:10

标签: json eclipse amazon-web-services amazon-cloudformation

我试图以与标准AWS模板相同的方式弄清楚如何自动格式化JSON文件。如果您通过AWS工具包或在线设计器运行模板,则格式非常易读。我在JSON编辑器中尝试过的所有东西看起来都像废话,但我看到大量的json格式的模板在网上看起来与亚马逊格式完全一样。我尝试过使用AWS工具包,但只识别名为“ .template 的文件。是否有不同的插件或我应该输入的自定义设置?

谢谢大家!

示例(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"
            ]
        }
    }
}

}

1 个答案:

答案 0 :(得分:0)

Visual Studio将它们完美地格式化,如果你手动将一个CRLF放到文件的末尾,它就会把它们变成完美的格式。