【问题标题】:AWS Golang S3 manager upload: Access deniedAWS Golang S3 管理器上传:访问被拒绝
【发布时间】:2020-11-10 04:24:38
【问题描述】:

我正在使用 S3 上传管理器将一个大文件上传到 S3。

if _, err := uploader.UploadWithContext(ctx, &s3manager.UploadInput{
        Bucket:          aws.String(s.Config.GetS3ExportBucket()),
        Key:             aws.String(key),
        Body:            bytes.NewReader(buf.Bytes()),
        ContentEncoding: aws.String("gzip"),
        ContentType:     aws.String("application/json"),
    }); err != nil {
        return fmt.Errorf("failed to upload file, %w", err)
    }

根据this AWS 文档,我也为我的 lambda 提供了权限。

#Created Policy for IAM Role
resource "aws_iam_policy" "s3_write_policy" {
  name        = "${local.namespace}-s3-write-access"
  description = "Allow Lambda to access s3 where back will be written"
  policy      = data.aws_iam_policy_document.s3_write_policy.json
}

data "aws_iam_policy_document" "s3_write_policy" {
  statement {
    sid       = "WriteObjectActions"
    effect    = "Allow"
    actions   = [
      "s3:AbortMultipartUpload",
      "s3:GetObject",
      "s3:ListBucket",
      "s3:ListBucketMultipartUploads",
      "s3:PutObject",]
    resources = [
      aws_s3_bucket.db_export.arn]
  }
}

但是,我不断收到来自 S3 的拒绝访问错误。

【问题讨论】:

  • 如果没有看到您要放入的 URL 和资源字符串,就不可能看到您是正确的。用 URL 和资源字符串替换敏感部分并重新发布。

标签: amazon-web-services go amazon-s3 aws-lambda terraform


【解决方案1】:

您不仅需要提供对存储桶的访问权限,还需要提供对存储桶内所有对象的访问权限。

试试这个政策

data "aws_iam_policy_document" "s3_write_policy" {
  statement {
    sid       = "WriteObjectActions"
    effect    = "Allow"
    actions   = [
      "s3:AbortMultipartUpload",
      "s3:GetObject",
      "s3:ListBucket",
      "s3:ListBucketMultipartUploads",
      "s3:PutObject",]
    resources = [
      aws_s3_bucket.db_export.arn,
      "${aws_s3_bucket.db_export.arn}/*"]
  }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-26
    • 1970-01-01
    • 2020-09-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-22
    • 2021-10-01
    相关资源
    最近更新 更多