AWS S3 策略仅限制我的 cloudFrontdistribution(通过 yaml cloudFormation)

问题描述 投票:0回答:1

我想创建 AWS S3 策略。我希望 AWS S3 不公开,并且仅通过我的 cloudFront 发行版进行访问。我阅读了所有文档,但没有找到 yaml 示例。

我尝试了此操作,但出现错误(策略无效):

BucketPolicy:
    Type: "AWS::S3::BucketPolicy"
    DependsOn: S3BucketFront
    Properties:
      Bucket: !Ref S3BucketFront
      PolicyDocument:
        Id: WebFrontBuildBucketPolicy
        Version: 2012-10-17
        Statement:
          - Sid: AllowCloudFrontServicePrincipal
            Effect: Allow
            Principal:
              Service:
                - cloudfront.amazonaws.com
            Action:
              - s3:GetObject
            Resource: "arn:aws:s3:::${AWS::AccountId}-${AWS::StackName}/*"
            Condition:
              StringEquals:
                "AWS:SourceArn": "arn:aws:cloudfront::${AWS::AccountId}:distribution/${CloudFrontdistribution}"
amazon-web-services amazon-s3 aws-cloudformation amazon-cloudfront
1个回答
0
投票

你应该使用

!Sub
:

Resource: !Sub "arn:aws:s3:::${AWS::AccountId}-${AWS::StackName}/*"

其他使用 CFN 变量的地方也一样。

© www.soinside.com 2019 - 2024. All rights reserved.