learner
learner

Reputation: 2840

CloudFormation error [/Resources] 'null' values are not allowed in templates

I have the below CF Template:

AWSTemplateFormatVersion: 2010-09-09
Description: >-
  Creating Maintenance Window for Non-Production Windows Server Patching.
Resources:
MaintenanceWindow:
  Type: AWS::SSM::MaintenanceWindow
  Properties:
    AllowUnassociatedTargets: false
    Cutoff: 1
    Description: Maintenance Window to update SSM Agent
    Duration: 6
    Name: MaintenanceWindowCFN
    Schedule: "cron(0 15 14 ? * MON *)"
    ScheduleTimezone: "Australia/Melbourne"
MaintenanceWindowTarget:
  Type: AWS::SSM::MaintenanceWindowTarget
  Properties:
    WindowId: !Ref MaintenanceWindow
    ResourceType: INSTANCE
    Targets:
    - Key: tag:Patch Group
      Values:
      - Group A
    OwnerInformation: SSM Target
    Name: SSMMaintenanceWindow
    Description: A target for demonstrating maintenance windows 
  DependsOn: MaintenanceWindow
MaintenanceWindowTask:
  Type: AWS::SSM::MaintenanceWindowTask
  Properties:
    WindowId: !Ref MaintenanceWindow
    Targets: 
      - Key: WindowTargetIds
        Values:
        - !Ref MaintenanceWindowTarget
    TaskArn: AWS-RunPatchBaseline
    TaskType: RUN_COMMAND
    TaskInvocationParameters:
      MaintenanceWindowAutomationParameters:
        Parameters:
          InstanceId:
            - "{{TARGET_ID}}"
          NoReboot:
            - "false"
    Priority: 1
    MaxConcurrency: 2
    MaxErrors: 1
    Name: Registration of Task with Targets
DependsOn: MaintenanceWindowTarget

And it reports an error like below:

[/Resources] 'null' values are not allowed in templates

Forgive me, I am new to CF but it would have been a much nice if AWS would have had come up with a Tool to identify what the error is and provide some with more helpful input to fix it rather than just last out the error!

Upvotes: 3

Views: 8481

Answers (2)

Chris Williams
Chris Williams

Reputation: 35188

This is an alignment issue with your YAML.

Here's the formatted version, your Resources value was at same level as the resources inside of it which caused Resources to appear as if its value was Null.

AWSTemplateFormatVersion: 2010-09-09
Description: >-
  Creating Maintenance Window for Non-Production Windows Server Patching.
Resources:
    MaintenanceWindow:
      Type: AWS::SSM::MaintenanceWindow
      Properties:
        AllowUnassociatedTargets: false
        Cutoff: 1
        Description: Maintenance Window to update SSM Agent
        Duration: 6
        Name: MaintenanceWindowCFN
        Schedule: "cron(0 15 14 ? * MON *)"
        ScheduleTimezone: "Australia/Melbourne"
    MaintenanceWindowTarget:
        Type: AWS::SSM::MaintenanceWindowTarget
        Properties:
            WindowId: !Ref MaintenanceWindow
            ResourceType: INSTANCE
            Targets:
              - Key: tag:Patch Group
                Values:
                  - Group A
            OwnerInformation: SSM Target
            Name: SSMMaintenanceWindow
            Description: A target for demonstrating maintenance windows 
        DependsOn: MaintenanceWindow
    MaintenanceWindowTask:
        Type: AWS::SSM::MaintenanceWindowTask
          Properties:
            WindowId: !Ref MaintenanceWindow
            Targets: 
              - Key: WindowTargetIds
                Values:
                  - !Ref MaintenanceWindowTarget
            TaskArn: AWS-RunPatchBaseline
            TaskType: RUN_COMMAND
            TaskInvocationParameters:
              MaintenanceWindowAutomationParameters:
                Parameters:
                  InstanceId:
                    - "{{TARGET_ID}}"
                  NoReboot:
                    - "false"
            Priority: 1
            MaxConcurrency: 2
            MaxErrors: 1
            Name: Registration of Task with Targets
        DependsOn: MaintenanceWindowTarget

Resources is the only key that is required in CloudFormation hence this error.

With YAML spacing and alignment are very important.

Upvotes: 3

Marcin
Marcin

Reputation: 238209

The template should be (indentation in Resources and DependsOn):

AWSTemplateFormatVersion: 2010-09-09
Description: >-
  Creating Maintenance Window for Non-Production Windows Server Patching.
Resources:
  MaintenanceWindow:
    Type: AWS::SSM::MaintenanceWindow
    Properties:
      AllowUnassociatedTargets: false
      Cutoff: 1
      Description: Maintenance Window to update SSM Agent
      Duration: 6
      Name: MaintenanceWindowCFN
      Schedule: "cron(0 15 14 ? * MON *)"
      ScheduleTimezone: "Australia/Melbourne"
  MaintenanceWindowTarget:
    Type: AWS::SSM::MaintenanceWindowTarget
    Properties:
      WindowId: !Ref MaintenanceWindow
      ResourceType: INSTANCE
      Targets:
      - Key: tag:Patch Group
        Values:
        - Group A
      OwnerInformation: SSM Target
      Name: SSMMaintenanceWindow
      Description: A target for demonstrating maintenance windows 
    DependsOn: MaintenanceWindow
  MaintenanceWindowTask:
    Type: AWS::SSM::MaintenanceWindowTask
    Properties:
      WindowId: !Ref MaintenanceWindow
      Targets: 
        - Key: WindowTargetIds
          Values:
          - !Ref MaintenanceWindowTarget
      TaskArn: AWS-RunPatchBaseline
      TaskType: RUN_COMMAND
      TaskInvocationParameters:
        MaintenanceWindowAutomationParameters:
          Parameters:
            InstanceId:
              - "{{TARGET_ID}}"
            NoReboot:
              - "false"
      Priority: 1
      MaxConcurrency: 2
      MaxErrors: 1
      Name: Registration of Task with Targets
    DependsOn: MaintenanceWindowTarget

Upvotes: 1

Related Questions