gpt4 book ai didi

amazon-web-services - 使用 cloudformation 模板创建 s3 存储桶时出现 ValidationError

转载 作者:行者123 更新时间:2023-12-03 07:40:04 25 4
gpt4 key购买 nike

我是 cloudformation 模板的新手。我正在尝试使用 codepipeline 创建一个 s3 存储桶。这是cloudformation模板:

---
AWSTemplateFormatVersion: 2010-09-09
Description: Template to create buckets and copy ymls to S3.

Parameters:
SPABucket:
Description: S3 bucket name for backend lambda functions
Type: String
Default: reference-data-migration-bucket-2021

Resources:
S3Bucketxls:
Type: AWS::S3::Bucket
Properties:
BucketName: !Sub ${SPABucket}-${AWS::AccountId}-${AWS::Region}
PublicAccessBlockConfiguration:
BlockPublicPolicy: true
IgnorePublicAcls: true
RestrictPublicBuckets: true
VersioningConfiguration:
Status: Enabled
AccessControl: Private
LoggingConfiguration:
DestinationBucketName: !Ref SpaLoggingBucket
LogFilePrefix: S3Bucketxls
BucketEncryption:
ServerSideEncryptionConfiguration:
- ServerSideEncryptionByDefault:
SSEAlgorithm: 'AES256'
Tags:
- Key: "sample"
Value: "test"

SpaLoggingBucket:
Type: AWS::S3::Bucket
Properties:
AccessControl: Private
Tags:
- Key: "sample"
Value: "test"


Outputs:
S3Bucketxlsx:
Description: The CodeDeploy role for a particular business service being deployed
Value: !GetAtt S3Bucketxls.Arn
Export:
Name: !Sub "${AWS::StackName}-S3BucketxlsArn"

我在使用 codepipeline 执行 Lint 时收到验证错误:

An error occurred (ValidationError) when calling the ValidateTemplateoperation: Invalid template resource property 'SpaLoggingBucket'

[Container] 2022/02/24 16:30:14 Command did not exit successfully awscloudformation validate-template --template-body file://${TMPLNAME}exit status 254 [Container] 2022/02/24 16:30:14 Phase complete: BUILDState: FAILED [Container] 2022/02/24 16:30:14 Phase context statuscode: COMMAND_EXECUTION_ERROR Message: Error while executing command:aws cloudformation validate-template --template-bodyfile://${TMPLNAME}. Reason: exit status 254

我该如何解决这个问题?

最佳答案

缩进在 YAML 中很重要,而且您的 SpaLoggingBucket block 似乎与 S3Bucketxls 等其他资源不一致,导致 CloudFormation 无法将其正确检测为资源。

将其向后移动一级对我来说很有效:

---
AWSTemplateFormatVersion: 2010-09-09
Description: Template to create buckets and copy ymls to S3.

Parameters:
SPABucket:
Description: S3 bucket name for backend lambda functions
Type: String
Default: reference-data-migration-bucket-2021

Resources:
S3Bucketxls:
Type: AWS::S3::Bucket
Properties:
BucketName: !Sub ${SPABucket}-${AWS::AccountId}-${AWS::Region}
PublicAccessBlockConfiguration:
BlockPublicPolicy: true
IgnorePublicAcls: true
RestrictPublicBuckets: true
VersioningConfiguration:
Status: Enabled
AccessControl: Private
LoggingConfiguration:
DestinationBucketName: !Ref SpaLoggingBucket
LogFilePrefix: S3Bucketxls
BucketEncryption:
ServerSideEncryptionConfiguration:
- ServerSideEncryptionByDefault:
SSEAlgorithm: 'AES256'
Tags:
- Key: "sample"
Value: "test"

SpaLoggingBucket:
Type: AWS::S3::Bucket
Properties:
AccessControl: Private
Tags:
- Key: "sample"
Value: "test"


Outputs:
S3Bucketxlsx:
Description: The CodeDeploy role for a particular business service being deployed
Value: !GetAtt S3Bucketxls.Arn
Export:
Name: !Sub "${AWS::StackName}-S3BucketxlsArn"

附注使用 JSON 的好处之一是不会遇到这样的事故。

关于amazon-web-services - 使用 cloudformation 模板创建 s3 存储桶时出现 ValidationError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71255324/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com