【问题标题】:Serverless framework lambda function access denied to S3S3 拒绝无服务器框架 lambda 函数访问
【发布时间】:2020-07-25 13:54:03
【问题描述】:

有人知道为什么我在尝试将对象放入 lambda 函数内的 S3 时会收到“拒绝访问”吗?我有具有 AdministorAccess 的无服务器 AWS 用户,并允许访问 serverless.yml 内的 s3 资源:

  iamRoleStatements:
    - Effect: Allow
      Action:
        - s3:PutObject
      Resource: "arn:aws:s3:::*"

编辑 - 这是文件

serverless.yml

service: testtest
app: testtest
org: workx

provider:
  name: aws
  runtime: nodejs12.x

  iamRoleStatements:
    - Effect: Allow
      Action:
        - s3:PutObject
      Resource: "arn:aws:s3:::*/*"

functions:
  hello:
    handler: handler.hello
    events:
      - http:
          path: users/create
          method: get

handler.js

'use strict';
const AWS = require('aws-sdk');

// get reference to S3 client
const S3 = new AWS.S3();

// Uload the content to s3 and allow download
async function uploadToS3(content) {
  console.log('going to upload to s3!');

  const Bucket = 'mtest-exports';
    const key = 'testtest.csv';

  try {
    const destparams = {
        Bucket,
        Key: key,
        Body: content,
        ContentType: "text/csv",
    };

    console.log('going to put object', destparams);
    const putResult = await S3.putObject(destparams).promise(); 

    return putResult;
  } catch (error) {
    console.log(error);
    throw error;
  } 
}

module.exports.hello = async event => {
  const result = await uploadToS3('hello world');

  return {
    statusCode: 200,
    body: JSON.stringify(result),
  };
};

【问题讨论】:

  • 试试"Resource": "*"?如果这没有帮助,请编辑您的问题以包含导致错误的代码。
  • 试试这个Resource: "arn:aws:s3:::*/*"
  • @JohnRotenstein 我试过了,没用
  • @ThanhNguyenVan 也试过你的方法,但没用
  • 请编辑您的问题以包含导致错误的代码。

标签: amazon-s3 aws-lambda serverless-framework serverless


【解决方案1】:

原来我是个白痴,把 custom 配置放在了错误的地方,毁掉了 serverless.yml 文件!

【讨论】:

  • 请分享。它看起来像什么?它应该在哪里?
猜你喜欢
  • 1970-01-01
  • 2021-04-25
  • 2020-09-30
  • 2021-05-19
  • 2020-01-25
  • 2018-08-15
  • 2016-09-29
  • 2021-02-01
  • 1970-01-01
相关资源
最近更新 更多