Write a file to S3

Hi everyone,

I am new to serverless and AWS Lambda. I want to write a .js file in my S3 bucket. What permission should I define in serverless.yml and how?

Now my code looks like this;
iamRoleStatements:
- Effect: “Allow”
Resource: S3Bucket*
Action:
- “s3:ListBucket”
- “s3:PutObject”

But it does not work.

Thanks.

Maybe start with “s3:*” to make sure your code works…?

Also post your complete serverless.yml so it is easier to pinpoint where it goes wrong.

Hi there,

Thanks for your answer. Here are my full serverless.yml

serverless.yml

service: my-express-application

provider:
name: aws
iamRoleStatements:
- Effect: “Allow”
Action:
- “s3:PutObject”
- “s3:DeleteObject”
- “s3:DeleteObjects”
- “s3:GetObject”
Resource: arn:aws:s3::AAAAAAAA
runtime: nodejs8.10
stage: dev
region: us-east-1
profile: serverless-admin

functions:
app:
handler: index.handler
events:
- http: ANY /
- http: ‘ANY {proxy+}’

My function is;

const serverless = require(‘serverless-http’);
const express = require(‘express’)
const app = express()

const AWS = require(‘aws-sdk’);
const s3 = new AWS.S3();

app.get(’/’, function (req, res) {

var params = {
Bucket: ‘AAAA’
};
s3.getBucketPolicyStatus(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
})

module.exports.handler = serverless(app);

But it does not work.

Hi, if you call s3.getBucketPolicy - you need to have the s3:GetBucketPolicyStatus permission. https://docs.aws.amazon.com/AmazonS3/latest/API/RESTBucketGETPolicyStatus.html
As for logs, what error did you get?