You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

CloudFormation创建ECR仓库报错:无效模板属性ImageRepoName求助

问题解决与修正后的ECR CloudFormation模板

错误原因分析

  1. 无效模板属性ImageRepoName:你的Outputs块缩进错误,被嵌套在Resources内部。CloudFormation将其识别为资源的非法属性,导致报错。需将Outputs调整为与Resources同级的顶层模块。
  2. 加密配置冲突:你同时设置了KmsMasterKeyId和EncryptionConfiguration,这两个属性互斥。使用EncryptionConfiguration指定KMS加密时,无需单独声明KmsMasterKeyId。

修正后的完整模板

AWSTemplateFormatVersion: '2010-09-09'
Parameters:
  ECRRepoName:
    Type: String
    Default: sample
  ECRkeyMLPlatform:
    Type: String
    Description: ARN or ID of the KMS key used for ECR encryption

Resources:
  EcrMlPlatform:
    Type: 'AWS::ECR::Repository'
    Properties:
      DisplayName: !Ref ECRRepoName
      EmptyOnDelete: true
      EncryptionConfiguration:
        EncryptionType: KMS
        KmsKey: !Ref ECRkeyMLPlatform
      ImageScanningConfiguration:
        scanOnPush: true
      ImageTagMutability: IMMUTABLE
      RepositoryName: !Ref ECRRepoName
      RepositoryPolicyText:
        Version: "2012-10-17"
        Statement:
          - Sid: AllowPull
            Effect: Allow
            Principal: "*"
            Action:
              - "ecr:GetDownloadUrlForLayer"
              - "ecr:BatchGetImage"
              - "ecr:BatchCheckLayerAvailability"
              - "ecr:DescribeImages"
              - "ecr:DescribeRepositories"

Outputs:
  ImageRepoName:
    Value: !Sub ${AWS::AccountId}.dkr.ecr.${AWS::Region}.amazonaws.com/${ECRRepoName}
    Description: Full URI of the ECR repository

关键说明

  • 参数段:补充了你提到的ECRRepoName参数,默认值设为你需要的sample,同时包含ECRkeyMLPlatform参数用于指定KMS密钥。
  • 加密配置:移除了冗余的KmsMasterKeyId,仅保留EncryptionConfiguration确保加密配置合法。
  • Outputs位置:调整为顶层元素,确保CloudFormation正确识别输出项。

内容的提问来源于stack exchange,提问作者dewdrops

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.01 17:22:29