【发布时间】:2020-04-29 20:21:45
【问题描述】:
我需要我的 csharp 应用程序来读取 cloudformation 模板 yaml 文件(带有 !Sub 和其他功能),以便将资源按原样复制到另一个具有不同资源名称的 cloudformation 模板 yaml 中。 YamlDotNet 在遇到 !Sub 和其他函数时无法反序列化。我应该使用另一个反序列化器吗?我可以将其软类型反序列化为字典字典,如字典
示例 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"] 复制到另一个文件中
【问题讨论】:
-
如果您提供更多背景信息,例如您尝试加载的文档示例,我或许可以为您提供帮助。
-
添加了一个例子,谢谢!
-
@Chip 你找到解决方案了吗?我也有同样的问题...
-
我最终改用 python 和 cfn_flip。如果您需要坚持使用 c#,也许您可以使用 cfn_flip 将 yaml 转换为 json,然后加载 json。这不是一个友好的设置,因为你会失去 cmets 等等。
标签: c# amazon-cloudformation yamldotnet