1

I'm setting up a lambda function that pulls file objects from s3. I kept getting timeout errors, and after investigation it seems like the place where the code hangs is where I call s3.get_object(...), where s3 = boto3.client('s3')

It looks like all code involving boto3 has issues, because the aws secrets manager (uses boto3.session) also hangs.

I wondered if it was a credentials issues, but thought it wasn't likely since it's running from within a lambda function.

s3 = boto3.client('s3')

def handler(event, context):
    """
    This function fetches content from MySQL RDS instance
    """
    print("Received event: " + json.dumps(event, indent=2))
    body_json = json.loads(event['Records'][0]['body'])
    bucket = body_json["Records"][0]["s3"]["bucket"]["name"]
    key = urllib.parse.unquote_plus(body_json["Records"][0]["s3"]['object']['key'], encoding='utf-8')

    #Everything runs up to this line, and hangs from here on out
    response = s3.get_object(Bucket=bucket, Key=key)

I think the strangest part is that everything about my code worked and functioned until a few hours ago, and I had no issues with s3. Not really sure what changed since I didn't change any of the lambda code...

user11875807
  • 11
  • 1
  • 5
  • Maybe you changed the lambda's IAM policy? This could explain why it stopped working without changing code – ketcham Aug 02 '19 at 19:46
  • See [This](https://stackoverflow.com/questions/50524727/can-not-access-s3-via-vpc-endpoint-in-lambda). When the lambda is in a VPC then it cannot connect to the S3 without proper settings. – Lamanus Aug 03 '19 at 02:28
  • How big is the object you are wanting to access? Have you tried increasing the timeout value of the Lambda function? (What is the timeout currently set to?) – John Rotenstein Aug 03 '19 at 07:04
  • @JohnRotenstein The object is about 67 kb, and yep, I tried increasing to 8 minutes and that still timed out. – user11875807 Aug 05 '19 at 13:21
  • Is the Lambda function configured to use a VPC? – John Rotenstein Aug 05 '19 at 23:53
  • @JohnRotenstein Yup, it's configured to do so. I had the correct (or so I think) permissions because it made connections earlier. – user11875807 Aug 06 '19 at 14:09
  • So the issue was closely related to what @Lamanus posted, if you see op's answer in that post he says things about using 2 private vpc's only which solved my issue. Thank you everyone! – user11875807 Aug 06 '19 at 15:01

1 Answers1

-1

You probably need to give your lambda permissions to use s3.

This might help

Nimirium
  • 69
  • 1
  • 9