amazon-web-services - CloudFormation 错误 [/Resources] 模板中不允许使用 'null' 值

标签 amazon-web-services aws-cloudformation

我有以下 CF 模板:

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] 'null' values are not allowed in templates

请原谅,我是 CF 新手,但如果 AWS 能够提供一个工具来识别错误是什么,并提供一些更有用的输入来修复它,而不是仅仅最后解决,那就太好了错误!

最佳答案

这是您的 YAML 的对齐问题。

这是格式化版本,您的 Resources 值与其内部的资源处于同一级别,这导致 Resources 显示为 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 是 CloudFormation 中所需的唯一 key ,因此会出现此错误。

对于 YAML,间距和对齐非常重要。

关于amazon-web-services - CloudFormation 错误 [/Resources] 模板中不允许使用 'null' 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62751273/

相关文章:

amazon-web-services - AWS Cloudformation 将条件函数解释为资源属性

Git不使用全局配置文件中的用户

grails - Amazon Cloud Web Services上的Grails应用程序 session 数据错误

amazon-web-services - AWS胶云形成数据库创建错误

amazon-web-services - 删除 CloudFormation 中无法操作的堆栈集

amazon-web-services - Api 网关与 Event Bridge 的连接出现错误。不支持 Eventbridge-PutEvents

amazon-web-services - 即使终止后,CodeDeploy 实例也会重新初始化

amazon-web-services - 使用 AWS 负载均衡器的安全 Web 套接字 (wss)

amazon-web-services - 检查 redis 数据存储中的空值?

amazon-web-services - 使用 get_template 从模板创建 CFN 堆栈