0

The lambda function handler below does not log anything after the line console.log('Getting already imported files list...');. The function just times out (30s for example).

The bucket 'testbucket' is not available (intentionally). Though, I am not getting any error messages or other log messages. How can I enable them?

import { ListObjectsV2Command, S3Client } from '@aws-sdk/client-s3';

export const handler = async (): Promise<unknown> => {
  try {
    const s3Client = new S3Client({
      region: 'eu-west-3',
      logger: {
        error: (...messages: string[]): void => console.log(...messages),
        warn: (...messages: string[]): void => console.log(...messages),
        info: (...messages: string[]): void => console.log(...messages),
        debug: (...messages: string[]): void => console.log(...messages),
      },
      maxAttempts: 1,
    });

    console.log('Getting already imported files list...');

    const res = await s3Client.send(
      new ListObjectsV2Command({
        Bucket: 'testbucket',
      }),
    );

    console.log({ res });

    console.log('Ended :)');

    return {
      statusCode: 200,
      message: 'ok?',
    };
  } catch (error) {
    console.log('Error caught...');

    console.log(error);

    return {
      statusCode: 500,
      message: 'Internal server error.',
    };
  }
};

michaelschufi
  • 109
  • 2
  • 10
  • Is this Lambda function running in a VPC? – Mark B Jun 03 '22 at 13:25
  • Try increasing your Lambda timeout to 300 seconds and you should see an error. – Parsifal Jun 03 '22 at 13:44
  • 1
    To explain what MarkB said: if you're running in a VPC, the only way for the Lambda to access anything outside the VPC is for (1) it to have a VPC endpoint, or (2) it's running in a subnet that routes external traffic through a NAT. – Parsifal Jun 03 '22 at 13:46
  • I guess that the VPC was the issue. However, the problem still was that I did not get any error logs at all. If something is inaccessible, I expect to have some error message that it is not accessible. – michaelschufi Jun 07 '22 at 15:15

0 Answers0