gpt4 book ai didi

amazon-web-services - AWS Cloudformation 模板 - S3 存储桶策略 - MalformedPolicy 错误

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

我尝试向我的(静态网站)S3 存储桶添加一项策略,以仅允许 CloudFormation 发行版访问它,但在部署过程中我仍然收到 MalformedPolicy 错误,并且找不到问题。

CloudFormation模板基本部分

Resources:

BucketPolicy:
Type: 'AWS::S3::BucketPolicy'
DependsOn:
- AppBucket
- CloudFrontDistribution
Properties:
Bucket: !Ref AppBucket
PolicyDocument:
Id: MyPolicy
Version: 2012-10-17
Statement:
- Sid: PolicyForCloudFrontPrivateContent
Action: 's3:GetObject*'
Effect: Allow
Condition:
StringLike:
'aws:Referer':
- !Sub 'https://*.${CloudFrontDistribution}.cloudfront.net/*'
Resource:
- !Sub arn:aws:s3:::${AppBucket}

CloudFrontDistribution:
# ...

AppBucket:
# ...

部署错误

(...)

CloudFormation events from stack operations (refresh every 0.5 seconds)
---------------------------------------------------------------------------------------------------------------------------------------------
ResourceStatus ResourceType LogicalResourceId ResourceStatusReason
---------------------------------------------------------------------------------------------------------------------------------------------
UPDATE_IN_PROGRESS AWS::S3::BucketPolicy BucketPolicy -
UPDATE_FAILED AWS::S3::BucketPolicy BucketPolicy Missing required field Principal
(Service: Amazon S3; Status Code:
400; Error Code: MalformedPolicy;
Request ID: DG2QHRDJQ2WS6JZV; S3
Extended Request ID: 6u+LYv77A4Ao
DmKmyB4Sfup+rueC1iGAQ82GdkfHimIZL
X/HXUPWj2FKSq7WCgi41F4XU6z6BOk=;
Proxy: null)
UPDATE_ROLLBACK_IN_PROGRESS AWS::CloudFormation::Stack test-app-hosting The following resource(s) failed
to update: [BucketPolicy].
UPDATE_COMPLETE AWS::S3::BucketPolicy BucketPolicy -
UPDATE_ROLLBACK_COMPLETE_CLEANUP_ AWS::CloudFormation::Stack test-app-hosting -
IN_PROGRESS
UPDATE_ROLLBACK_COMPLETE AWS::CloudFormation::Stack test-app-hosting -
---------------------------------------------------------------------------------------------------------------------------------------------
Error: Failed to create/update the stack: test-app-hosting, Waiter StackUpdateComplete failed: Waiter encountered a terminal failure state: For expression "Stacks[].StackStatus" we matched expected path: "UPDATE_ROLLBACK_COMPLETE" at least once

更新#1

正如机器人 @luk2302 和 @Marcin 指出的那样,我错过了 Statement > Principal 部分(感觉很愚蠢),但添加它现在给出了一个新的错误:

---------------------------------------------------------------------------------------------------------------------------------------------
ResourceStatus ResourceType LogicalResourceId ResourceStatusReason
---------------------------------------------------------------------------------------------------------------------------------------------
UPDATE_IN_PROGRESS AWS::S3::BucketPolicy BucketPolicy -
UPDATE_FAILED AWS::S3::BucketPolicy BucketPolicy Invalid policy syntax. (Service:
Amazon S3; Status Code: 400;
Error Code: MalformedPolicy;
Request ID: NH6PZB3QF0747F4N; S3
Extended Request ID: xdXOFPWgHCjg
Lzf4gdjCg79NIXS6qtmtLuGn8N7NeLIOJ
4Qw2bgSJ2v6MKdNzbrMCWCEPKBc90E=;
Proxy: null)
UPDATE_ROLLBACK_IN_PROGRESS AWS::CloudFormation::Stack test-app-hosting The following resource(s) failed
to update: [BucketPolicy].

最佳答案

Resource 的意图不正确,并且您缺少 Principal,如 AWS docs 中所述。 。应该是:

  BucketPolicy:
Type: 'AWS::S3::BucketPolicy'
DependsOn:
- AppBucket
- CloudFrontDistribution
Properties:
Bucket: !Ref AppBucket
PolicyDocument:
Id: MyPolicy
Version: 2012-10-17
Statement:
- Sid: PolicyForCloudFrontPrivateContent
Action: 's3:GetObject*'
Effect: Allow
Principal:
Service: cloudfront.amazonaws.com
Resource:
- !Sub arn:aws:s3:::${AppBucket}
Condition:
StringLike:
'aws:Referer':
- !Sub 'https://*.${CloudFrontDistribution}.cloudfront.net/*'

关于amazon-web-services - AWS Cloudformation 模板 - S3 存储桶策略 - MalformedPolicy 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75207837/

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