3

I have created a user in the AWS console with access only to the Lambda service.

My question is, using the serverless framework, in my serverless.yaml, is it possible to add S3 Full access to my user and possibly any other service? Thank you.

handler.js

 'use strict';
const aws = require('aws-sdk');
const s3 =  new aws.S3({ apiVersion: '2006-03-01' });

module.exports.helloWorld = (event, context, callback) => {

  const params = {};
  s3.listBuckets(params, function(err, data) {
    if (err) console.log(err, err.stack); 
    else     console.log(data);          
  });

  const response = {
    statusCode: 200,
    message: JSON.stringify({message: 'Success!'})
  };
  callback(null, response);
};

serverless.yaml

provider:
  name: aws
  runtime: nodejs8.10
  region: eu-blah-1
  iamRoleStatements:
    - Effect: "Allow"
      Action:
        - "s3:ListBucket"
        - "s3:PutObject"
        - "s3:GetObject"
      Resource: "arn:aws:s3:::examplebucket/*"


functions:
  helloWorld:
    handler: handler.helloWorld
    events:
      - http:
          path: hello-world
          method: get
          cors: true
4

1 に答える 1