AWS CloudFormation 属性验证失败:[在 {/ContainerProperties/Environment 中遇到不受支持的属性

时间:2021-01-11 08:35:32

标签: yaml amazon-cloudformation

我正在使用 AWS Batch 创建 POC。为了创建基础设施,我使用了 AWS CloudFormation。

我对资源 AWS::Batch::JobDefinition

有问题
  ContentInputJob:
    Type: "AWS::Batch::JobDefinition"
    Properties:
      Type: Container
      ContainerProperties: 
        Environment:
          - name: SECRETS
            value: '**********'
        Command: 
          - -v
          - process
          - new-file
          - -o
        Image: !Join ['', [!Ref 'AWS::AccountId','.dkr.ecr.', !Ref 'AWS::Region', '.amazonaws.com/', !Ref ImageName ] ]
        JobRoleArn: !Ref BatchContainerIAMRole
        Memory: 128 
        Vcpus: 2
      JobDefinitionName: DemoContentInput
      RetryStrategy: 
        Attempts: 1

创建堆栈失败,并显示...“属性验证失败:[在 {/ContainerProperties/Environment/0} 中遇到不受支持的属性:[名称,值]]”

我读过:

我也试过这个:

  ContentInputJob:
    Type: "AWS::Batch::JobDefinition"
    Properties:
      Type: Container
      ContainerProperties: 
        Environment:
          - SECRETS: '**********'
        Command: 
          - -v
          - process
          - new-file
          - -o
        Image: !Join ['', [!Ref 'AWS::AccountId','.dkr.ecr.', !Ref 'AWS::Region', '.amazonaws.com/', !Ref ImageName ] ]
        JobRoleArn: !Ref BatchContainerIAMRole
        Memory: 128 
        Vcpus: 2
      JobDefinitionName: DemoContentInput
      RetryStrategy: 
        Attempts: 1

然后我得到“属性验证失败:[在 {/ContainerProperties/Environment/0} 中遇到不受支持的属性:[SECRETS]]”

它的语法如何?我需要多个环境变量。

      ContainerProperties: 
        Environment:
          - name: SECRETS
            value: '**********'
          - name: SECRETS2
            value: '**********'

2 个答案:

答案 0 :(得分:0)

解决方案是使用大写字母。

      ContainerProperties: 
        Environment:
          - Name: SECRETS
            Value: '**********'
          - Name: SECRETS2
            Value: '**********'

答案 1 :(得分:0)

建议尝试使用 CloudFormation Linter 中的 VSCode 在创作模板以及自动完成和文档链接时内联查看其中一些错误:

Visual Studio Code extension

[cfn-lint] E3002: Invalid Property Resources/ContentInputJob/Properties/ContainerProperties/Environment/0/name
[cfn-lint] E3002: Invalid Property Resources/ContentInputJob/Properties/ContainerProperties/Environment/0/value