How should i specify params for s3.putObject() ? (node.js)

Hello everybody! I am new to this so sorry for such silly question :smiley:
I’m trying to update my .csv file in s3 bucket but got no clue how to handle it.
Seems like i found the right method but still have nothing in the end.
Let me show u how i do this.

const params ={

    Bucket: 'myBucketName',

    Key: 'something.csv',

    Body: JSON.stringify(itemToUpload)

}

s3.putObject(params).promise();

I’m trying to specify my bucket in .yml file but it rejects with an error like “Bucket already exists”.
What should i do to solve my problem?

Post full code should be better

const AWS = require(‘aws-sdk’);

const documentClient = new AWS.DynamoDB.DocumentClient();

const s3 = new AWS.S3({ region: ‘eu-west-1’ });

const bucketName = process.env.bucketName;

const fiveMinsInMili = process.env.fiveMinsInMili;

exports.handler = async event => {

console.log('event', event);

console.log('save to s3 lambda');

const nowTimestamp = new Date().getTime();

const params = {

    TableName: 'Weather',

    Select: "ALL_ATTRIBUTES"

};

const items = await documentClient.scan(params).promise();

const { Items } = items; 

s3.putObject(params).promise();

Items.map(i => {

    if (nowTimestamp - i.timestamp <= fiveMinsInMili) {

        const putParams = {

            Bucket: bucketName,

            Key: 'weather.csv',

            Body: JSON.stringify(i)

        }

        s3.putObject(putParams, (err) => {

            if (err) console.log(err);

            else console.log('Its OK!');

        })

}})

};

I solved it with adding

  • Effect: “Allow”

    Action:
    
      "s3:*"
    
    Resource: '*'
    

to .yml file :slight_smile: