json - Eclipse:使用 Json 编辑器插件自动格式化 JSON 文件,例如 AWS Cloudformation Template

标签 json eclipse amazon-web-services aws-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"
            ]
        }
    }
}

}

最佳答案

如果您手动将 CRLF 放入文件末尾,Visual Studio 会完美地格式化它们,它会将它们转换为完美的格式。

关于json - Eclipse:使用 Json 编辑器插件自动格式化 JSON 文件,例如 AWS Cloudformation Template,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43520011/

相关文章:

json - N1QL 数组查询 where 条件检查内部元素

javascript - 动态显示 HTML 下拉菜单中的嵌套 JSON

java - IntelliJ 可以从 log4j 输出创建指向源代码的超链接吗?

eclipse - 为什么在启动 tomcat 服务器时会出现 ClassNotFoundException?

amazon-web-services - 从 AWS 上的 docker 容器内提供 Jupyter Notebook 无法正常工作?

security - JSON 响应周围的注释 block

javascript - AngularJS $HTTP.json

java - 在 UI 线程中注册 Saveable 时出现 ClassCastException

javascript - 我们如何在 Web 浏览器中使用 AWS Kinesis?

javascript - AWS Cognito Admin 创建用户临时密码验证和重置