0

For some strange reason, Lambda (Python3.8) is not able to connect to S3 bucket using Role. It just returns Timed Out error. It does not even throw any exception. It Times Out when this section is called response = s3.list_buckets()

I have even checked flow log of the Lambda ENI. They are returning no-data.

However, the same setting is working in another project.

Here is the code sample:

import json
import datetime
import time
import config as cf
import boto3
import botocore
from botocore.exceptions import ClientError

def lambda_handler(event, context):
    try:
        # Retrieve the list of existing buckets
        s3 = boto3.client('s3')
        response = s3.list_buckets()
        
        # Output the bucket names
        print('Existing buckets:')
        for bucket in response['Buckets']:
            print(f'  {bucket["Name"]}')
        
    except Exception as e:
        print("Exception:\n" + str(e))

    # TODO implement
    return {
        'statusCode': 200,
        'body': json.dumps('Hello from Lambda!')
    }

Has anyone faced any such problem?

A little help/advice would be really appreciated, I have been struggling for the last 2 days and I have to submit my work.

Thanks in advance.

Cheers,

Suman

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470

1 Answers1

0

The problem was that I created my NAT Gateway using a Private Subnet. I changed the NAT Gateway to a Public Subnet and it worked like a charm.

I do not need a VPC Endpoint to connect to S3 or any other services which are within my VPC.

charlesreid1
  • 4,360
  • 4
  • 30
  • 52