我不知道如何将 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
虽然我知道不需要这种转换,因为 json 和 yaml 在 cloudformation 中的工作方式相同,但必须按照要求执行此操作。
请您参考如下方法:
如果您需要一个命令行解决方案来从 JSON 转换为 YAML,反之亦然,请考虑 aws-cfn-template-flip项目。
安装库:
▶ pip install cfn_flip
用法:
▶ 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.
如果您的 CloudFormation 模板位于 YAML 中,那么您可以使用以下方法将其转换为 JSON:
▶ cfn-flip -j cloudformation.yml | jq . > cloudformation.json
JQ 的使用是可选的,只是为了清理格式。




