[英]How do I deserialize a cloudformation template yaml into a C# Dictionary of Strings?
我需要我的 csharp 应用程序来读取 cloudformation 模板 yaml 文件(带有、Sub 和其他功能),以便按原样复制资源。 进入另一个具有不同资源名称的 cloudformation 模板 yaml。 YamlDotNet 在遇到?Sub 和其他函数时无法反序列化,我应该使用另一个反序列化器,我可以将其软类型反序列化为字典字典,如 Dictionary <String? 字典<字符串。 字符串>>? 然后我可以将整个小节作为一个字符串读取并复制,而不必解析它。
示例 cf.yaml:
Description: my cloudformation example
Parameters:
MyParameter:
Description: What do you want?
Type: String
Default: 'hello'
Environment:
Description: Where do you want?
Type: String
Default: 'world'
Conditions:
# Enable Permission Boundary
IsBoundaryEnabled: !Equals [!Ref MyParameter, 'hello']
Resources:
MyPolicies:
Type: AWS::IAM::Policy
Properties:
PolicyName: My-Policies
PolicyDocument:
Statement:
-
Effect: Allow
Action:
- ssm:GetParameter
Resource:
- !Sub 'arn:aws:ssm:${AWS::Region}:${AWS::AccountId}:parameter/${Environment}.connectionString'
Roles:
- !Ref MyRole
MyRole:
Type: AWS::IAM::Role
Properties:
PermissionsBoundary: !If [ IsBoundaryEnabled, !Sub 'arn:aws:iam::${AWS::AccountId}:policy/My-Permission-Boundary', !Ref "AWS::NoValue"]
AssumeRolePolicyDocument:
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action:
- sts:AssumeRole
Path: /
所以我只想将 mycf["Resources"]["MyPolicies"] 复制到另一个文件
阅读 CloudFormation 并不容易! 涉及的困难很多。
我最近发布了一个nuget package来读写 CloudFormation,上面的链接是文档的一部分。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.