Bagbyte
Bagbyte

Reputation: 863

AWS Lambda error while accessing S3 bucket

I have a Lambda function triggered by a put event in an S3 bucket. When a file is added to the bucket, the lambda is correctly triggered, but it performs s3.getObject(params, (err, data) => {}) nothing happens.

The role of the Lambda function has the S3FullAccess policy attached.

I've tested the lambda locally (using sam) and everything works perfectly, but when the lambda is deployed nothing happens, no idea how to debug it neither.

const aws = require('aws-sdk');
const s3 = new aws.S3();
const bucket = event.Records[0].s3.bucket.name;
const key = event.Records[0].s3.object.key;

s3.getObject({Bucket: bucket, Key: key}, function(err, data) {
  if (err) {
    console.error(err);
  }

  console.log(data);
});

The scope of my lambda is:

  1. Read a CSV file from a private S3 bucket
  2. Load the content of the CSV files in a Database in a VPC

In order to let the lambda access the DB I've configured the lambda on the same VPC as the database.

Any idea?

Upvotes: 1

Views: 867

Answers (1)

Bagbyte
Bagbyte

Reputation: 863

The problem was that the Lambda was in a VPC in order to connect to the DB, but because of that has no access to the S3 bucket. To solve it I've created an Endpoint for the S3 Bucket and added it to my private Route Table.

Upvotes: 1

Related Questions