在json和yaml格式之间转换aws cloudformation模板

cfn-flip的Python项目详细描述


Build StatusPyPI versionCodecov Test CoverageSnap Status

Get it from the Snap Store

AWS云信息模板翻转

关于

aws cloudformation template flip是一个在JSONYAML格式之间转换AWS CloudFormation模板的工具,尽可能使用yaml格式的短函数语法。

术语“flip”的灵感来自于著名的unix命令行工具flip,它可以在unix、mac和ms-dos格式之间转换文本文件。

安装

可以使用pip安装AWS CloudFormation Template Flip:

pip install cfn_flip

用法

aws cloudformation template flip既是一个命令行工具,也是一个python库。

注意,命令行工具的拼写为带连字符的cfn-flip,而python包的拼写为带下划线的cfn_flip

命令行工具

Usage: cfn-flip [OPTIONS] [INPUT] [OUTPUT]

  AWS CloudFormation Template Flip is a tool that converts AWS
  CloudFormation templates between JSON and YAML formats, making use of the
  YAML format's short function syntax where possible."

Options:
  -i, --input [json|yaml]   Specify the input format. Overrides -j and -y
                            flags.
  -o, --output [json|yaml]  Specify the output format. Overrides -j, -y, and
                            -n flags.
  -j, --json                Convert to JSON. Assume the input is YAML.
  -y, --yaml                Convert to YAML. Assume the input is JSON.
  -c, --clean               Performs some opinionated cleanup on your
                            template.
  -l, --long                Use long-form syntax for functions when converting
                            to YAML.
  -n, --no-flip             Perform other operations but do not flip the
                            output format.
  --version                 Show the version and exit.
  --help                    Show this message and exit.

cfn flip将检测输入模板的格式,并分别将JSON转换为YAML和YAML转换为JSON

示例:

  • stdin读取并输出到stdout

    cat examples/test.json | cfn-flip
    
  • 从文件读取并输出到stdout

    cfn-flip examples/test.yaml
    
  • 从文件读取并输出到另一个文件:

    cfn-flip examples/test.json output.yaml
    
  • 读取文件并清除输出

    cfn-flip -c examples/test.json
    

python包

要从您自己的python项目中使用AWS CloudFormation Template Flip,请根据需要导入函数flipto_yamlto_json

fromcfn_flipimportflip,to_yaml,to_json"""All functions expect a string containing serialised dataand return a string containing serialised dataor raise an exception if there is a problem parsing the input"""# flip takes a best guess at the serialisation format# and returns the opposite, converting json into yaml and vice versasome_yaml_or_json=flip(some_json_or_yaml)# to_json expects serialised yaml as input, and returns serialised jsonsome_json=to_json(some_yaml)# to_yaml expects serialised json as input, and returns serialised yamlsome_yaml=to_yaml(some_json)# The clean_up flag performs some opinionated, CloudFormation-specific sanitation of the input# For example, converting uses of Fn::Join to Fn::Sub# flip, to_yaml, and to_json all support the clean_up flagclean_yaml=to_yaml(some_json,clean_up=True)

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
JavaSpring重定向请求处理程序   SwingJava:拆分字符串并将其放入文本区域的   Java:标记“”上出现语法错误,此标记后面应为表达式   web服务Java RestService从日志文件写入和读取数据   java如何将ArrayList<String>转换为char数组,然后向后打印每个单词?   java SimpleDataFormat解析返回年终日期   加密Java aes解密bytebuffer,包括填充为空字节   java有没有办法从特定的if语句调用变量?   java从更新返回到渲染   spring GRPC Java登录测试   java为什么下面的代码不工作(StringBuffer.toString!=null)   java是一种可行的模式吗?   使用Spring集成测试的JavaOSGi片段   java jCommander为未知和未使用的值引发异常?   在imageView的editText中输入的java图像URL