Серверный каркас лямбда-функции запрещен доступ к S3 - PullRequest
0 голосов
/ 13 апреля 2020

У кого-нибудь есть идеи, почему я получаю «Отказ в доступе» при попытке поместить объект в S3 внутри лямбда-функции? У меня есть серверный AWS пользователь с AdministorAccess и я разрешаю доступ к ресурсу s3 внутри serverless.yml:

  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

обработчик. 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),
  };
};

1 Ответ

0 голосов
/ 13 апреля 2020

Оказывается, я был идиотом, у меня неправильная конфигурация custom и испортил файл serverless.yml !

...