将Yaml cloudformation模板转换为Json

Nax*_*axi 2 aws-cloudformation

我不知道如何将yaml cloudformation模板的以下部分转换为json模板。任何人都可以在这里指导我。

Tags: 
- Key: Name 
  Value: !Join 
        - '' 
        - - !FindInMap  
              - BusinessUnitCode 
              - !Ref BusinessUnit 
              - Code 
          - A 
          - !FindInMap  
              - AWSRegionCode 
              - !Ref 'AWS::Region' 
              - Code 
          - '-' 
          - !FindInMap  
              - AccountsCode 
              - !Ref Account 
              - Code 
          - '-' 
          - !FindInMap  
              - ProdLevelCode 
              - !Ref ProductionLevel 
              - Code 
          - '-' 
          - !FindInMap  
              - ServerFunctionCode 
              - !Ref ServerFunction 
              - Code 
          - '-' 
          - !FindInMap  
              - SGFunctionCode 
              - !Ref SecurityGroupFunction 
              - Code 
          - '-'                   
          - !Ref IncrementCode
Run Code Online (Sandbox Code Playgroud)

尽管我知道没有必要进行此转换,因为json和yaml在cloudformation中的工作原理相同,但必须根据授权执行此操作。

DC.*_*lls 11

我用这个,它就像一个魅力: https: //cfnflip.com/

您可以将 JSON 转换为 YAML,以及将 YAML 转换为 JSON。

复制/粘贴都会检测并翻转。如果您也想将其设置为您自己的内部,则可以使用开源和源代码。(不,这不是我的,也不是赞助的)。

这不仅仅是一个普通的翻转工具,它专门针对 CloudFormation 工作。


Ale*_*vey 6

如果您想要一个命令行解决方案来从 JSON 转换为 YAML,反之亦然,请考虑aws-cfn-template-flip项目。

安装库:

? pip install cfn_flip
Run Code Online (Sandbox Code Playgroud)

用法:

? 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.
Run Code Online (Sandbox Code Playgroud)

如果您在 YAML 中有 CloudFormation 模板,那么您可以使用以下方法将其翻转为 JSON:

? cfn-flip -j cloudformation.yml | jq . > cloudformation.json
Run Code Online (Sandbox Code Playgroud)

JQ 的使用是可选的,只是为了清理格式。


Vik*_*yol 5

AWS控制台可以帮助您。在模板设计器中打开您的CloudFormation模板。

CloudFormation>选择堆栈>模板>在设计器中查看

然后,您可以通过选择模板语言为Json轻松地转换模板。