I need my csharp app to read a cloudformation template yaml file (with !Sub and other functions) in order to copy the resource, as-is, into another cloudformation template yaml with a different resource name. The YamlDotNet fails to deserialize when it hits the !Sub and other functions. Is there another deserializer I should use? Can I soft-type deserialize it into a Dictionary of Dictionaries like Dictionary <String, Dictionary<String, String>>? Then I could just read the whole subsection as a String to copy over and not have to parse it.
Example 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: /
So I just want to copy mycf["Resources"]["MyPolicies"] to another file