gpt4 book ai didi

amazon-s3 - 如何解决 "specified origin access identity does not exist or is not valid"

转载 作者:行者123 更新时间:2023-12-03 09:54:46 25 4
gpt4 key购买 nike

我的 serverless.yml 中的这些行有问题文件。
我正在使用无服务器插件 serverless-single-page-app-plugin .

# CustomOriginConfig:
# HTTPPort: 80
# HTTPSPort: 443
# OriginProtocolPolicy: https-only
## In case you want to restrict the bucket access use S3OriginConfig and remove CustomOriginConfig
S3OriginConfig:
OriginAccessIdentity: origin-access-identity/cloudfront/E127EXAMPLE51Z

我要使用 s3OriginConfig并禁用通过 S3 存储桶的访问。我可以手动执行此操作。但我想得到如下图所示的效果:

AWS Console config

最佳答案

您可能已经解决了它,因为您很久以前就问过您的问题,但如果您不这样做,这可能会有所帮助。我也遇到了同样的问题,经过 AWS 文档的一些研究后,我知道如何使用所需的属性。关于您的问题,需要考虑以下几点。

  • 由于您的来源是 Amazon S3 存储桶,您应该使用 S3OriginConfig 在分布。
  • 如果需要新的 OAI,那么您必须创建一个 CloudFrontOriginAccessIdentity 资源并将 OAI 和 S3CanonicalUserId 属性引用到 CloudFront 分发 S3BucketPolicy 资源分别。

  • 请找到以下代码段来回答您的问题。
    WebAppDistribution:
    Type: AWS::CloudFront::Distribution
    Properties:
    DistributionConfig:
    Origins:
    - DomainName: 'passport-front.s3.amazonaws.com'
    Id: 'WebApp'
    S3OriginConfig:
    OriginAccessIdentity: !Join ['', ['origin-access-identity/cloudfront/', !Ref CloudFrontOAI]]
    CloudFrontOAI:
    Type: AWS::CloudFront::CloudFrontOriginAccessIdentity
    Properties:
    CloudFrontOriginAccessIdentityConfig:
    Comment: 'access-identity-passport-front.s3.amazonaws.com'
    WebAppBucket:
    Type: AWS::S3::Bucket
    DeletionPolicy: "Retain"
    Properties:
    AccessControl: PublicRead
    BucketName: "passport-front"
    WebAppBucketPolicy:
    Type: AWS::S3::BucketPolicy
    Properties:
    Bucket: !Ref WebAppBucket
    PolicyDocument:
    Statement:
    - Action: s3:GetObject
    Effect: Allow
    Principal:
    CanonicalUser: !GetAtt CloudFrontOAI.S3CanonicalUserId
    Resource: !Join ['', ['arn:aws:s3:::', !Ref 'WebAppBucket', /*]]

    References: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/quickref-cloudfront.html

    关于amazon-s3 - 如何解决 "specified origin access identity does not exist or is not valid",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55496081/

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