Hairloss
Hairloss

Reputation: 13

AWS Lambda Python S3 with boto3, no idea why I'm getting an error

I've commented out all other code and moved this to the top. Still getting an error, not sure why at all. I've confirmed IAM's are correct this Lambda function has the S3FullAccess attached to it. I've been stuck on this for a while now, everything I've found in searching hasn't been helpful :/ my original code uses

import os
import pymysql
import json
import sys
import logging
import boto3
import zipfile
import tempfile

# logging.getLogger().setLevel(logging.INFO)
# logger = logging.getLogger()
# logger.setLevel(logging.INFO)

s3 = boto3.client('s3')

bucket = 'packages'
key = 'Packages/1005/v1005/1005.pkg'

def lambda_handler(event, context):
    try:
        data = s3.get_object(Bucket=bucket, Key=key)
        json_data = data['Body']

        return {
            'statusCode': '200',
            'body': str(type(json_data)),
        }

    except Exception as e:
        print(e)
        raise e

    sys.exit()

After I execute here are my results, I've increased the timeout from the default to 20s in case maybe it was just timing out:

{
  "errorMessage": "2020-03-10T03:49:45.400Z c51405a5-9eed-4167-8b6f-edf36beb9c15 Task timed out after 20.02 seconds"
}

Request ID:
"c51405a5-9eed-4167-8b6f-edf36beb9c15"

Function Logs:
START RequestId: c51405a5-9eed-4167-8b6f-edf36beb9c15 Version: $LATEST
END RequestId: c51405a5-9eed-4167-8b6f-edf36beb9c15
REPORT RequestId: c51405a5-9eed-4167-8b6f-edf36beb9c15  Duration: 20018.46 ms   Billed Duration: 20000 ms   Memory Size: 128 MB Max Memory Used: 81 MB  Init Duration: 382.35 ms    
2020-03-10T03:49:45.400Z c51405a5-9eed-4167-8b6f-edf36beb9c15 Task timed out after 20.02 seconds```

Upvotes: 1

Views: 2400

Answers (1)

Vlad
Vlad

Reputation: 9481

Is your lambda running inside of the VPC subnet? In that case you have to have a correct network setup. The subnet either needs to have a gateway to the public internet or preferably have an S3 endpoint configured inside of the VPC. In addition to the routing setup the security groups of the lambdas must allow access to the S3 as well.

Upvotes: 6

Related Questions