CloudFormation创建ECR仓库报错:无效模板属性ImageRepoName求助
问题解决与修正后的ECR CloudFormation模板
错误原因分析
- 无效模板属性ImageRepoName:你的
Outputs块缩进错误,被嵌套在Resources内部。CloudFormation将其识别为资源的非法属性,导致报错。需将Outputs调整为与Resources同级的顶层模块。 - 加密配置冲突:你同时设置了
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
相关产品推荐
相关产品推荐

