0

我使用Bref ( https://bref.sh/ )。我尝试使用AWS S3配置serverless.yml文件,以存储 img、css、js 等资产。当我使用“无服务器部署”命令进行部署时,出现此错误:

发生错误:AssetsBucketPolicy - API: s3:PutBucketPolicy 访问被拒绝。

在我的 AWS 账户中,我拥有“AdministratorAccess”权限(https://www.youtube.com/watch?v=KngM5bfpttA&list=PL0_-jlAhLRgEcU0P0Ivi4OO844pgrzJOU&index=2&t=0s

策略管理员访问

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": "*",
            "Resource": "*"
        }
    ]
}

我的 serverless.yml 文件是:

service: bref-demo-symfony

provider:
    name: aws
    region: us-east-1
    runtime: provided
    environment:
        # Symfony environment variables
        APP_ENV: prod

plugins:
    - ./vendor/bref/bref

functions:
    website:
        handler: public/index.php
        timeout: 28 # in seconds (API Gateway has a timeout of 29 seconds)
        layers:
            - ${bref:layer.php-73-fpm}
        events:
            -   http: 'ANY /'
            -   http: 'ANY /{proxy+}'
    console:
        handler: bin/console
        timeout: 120 # in seconds
        layers:
            - ${bref:layer.php-73} # PHP
            - ${bref:layer.console} # The "console" layer

resources:
    Resources:
        # The S3 bucket that stores the assets
        Assets:
            Type: AWS::S3::Bucket
            Properties:
                BucketName: my-unique-serverless-assets-bucket
        # The policy that makes the bucket publicly readable
        AssetsBucketPolicy:
            Type: AWS::S3::BucketPolicy
            Properties:
                Bucket: !Ref Assets # References the bucket we defined above
                PolicyDocument:
                    Statement:
                        -   Effect: Allow
                            Principal: '*' # everyone
                            Action: 's3:GetObject' # to read
                            Resource: 'arn:aws:s3:::my-unique-serverless-assets-bucket/*' # things in the bucket

在 AWS S3 上,我尝试在存储桶上添加一个策略

 {
  "Id": "Policy1573043469280",
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "Stmt1573043465451",
      "Action": "s3:*",
      "Effect": "Allow",
      "Resource": "arn:aws:s3:::bref-demo-symfony-dev-serverless-assets/assets",
      "Principal": "*"
    }
  ]
}

我有一条消息,例如“拒绝访问”、“您无法授予公共访问权限,因为此帐户的阻止公共访问设置已打开。要确定哪些设置已打开,请检查您的阻止公共访问设置。” 为什么 ?

没看懂怎么配置?这个权限(AdministratorAccess)还不够?

谢谢!

4

3 回答 3

-1

从文档中,您可以看到:

要解决“拒绝访问”错误,请检查以下内容:

您的 IAM 身份同时拥有s3:GetBucketPolicy和 的权限s3:PutBucketPolicy

https://aws.amazon.com/premiumsupport/knowledge-center/s3-access-denied-bucket-policy/

请检查您为 Lambda 函数配置的角色是否具有此权限。

您可以在“执行角色”部分看到这一点: 在此处输入图像描述 在这里您可以看到我的 Lambda 函数具有角色“克劳迪娅-快递-执行者”。

您也可以单击它,并详细检查该角色权限是什么。

于 2019-11-06T01:31:36.260 回答
-1

iamRoleStatements例如,如果您需要获取和放置对象,请尝试添加此代码iamRoleStatements,例如:

provider:
  name: aws
  runtime: nodejs10.x
  region: us-west-2
  profile: ${self:custom.profiles.${self:custom.myStage}}
  iamRoleStatements:
    - Effect: "Allow"
      Action:
        - "s3:PutObject"
        - "s3:GetObject"
      Resource:
        - "*"

这是另一个例子:

provider:
  name: aws
  iamRoleStatements:
    - Effect: 'Allow'
      Action:
        - 's3:ListBucket'
      Resource:
        Fn::Join:
          - ''
          - - 'arn:aws:s3:::'
            - Ref: ServerlessDeploymentBucket
    - Effect: 'Allow'
      Action:
        - 's3:PutObject'
      Resource:
        Fn::Join:
          - ''
          - - 'arn:aws:s3:::'
            - Ref: ServerlessDeploymentBucket
            - '/*'

如果您需要更多信息,请阅读无服务器文档: 无服务器 IAM 角色

于 2019-11-06T05:54:37.463 回答
-1
  1. 检查存储桶策略
  2. 如果涉及存储桶策略,请添加您为无服务器创建的用户
  3. 检查下图以获取示例存储桶策略 https://docs.aws.amazon.com/AmazonS3/latest/user-guide/add-bucket-policy.html在此处输入图像描述
于 2019-11-06T02:15:06.317 回答