简体   繁体   English

Lambda 从 S3 检索数据时挂起的容器映像 (Docker ECR) 构建

[英]Lambda built from container image (Docker ECR) hanging when retrieving data from S3

I have a lambda function that uses a Docker container stored in ECR.我有一个 lambda function 使用存储在 ECR 中的 Docker 容器。

When I test the image locally I have no issues at all, however when I deploy it in lambda it fails due to timeout (no matter the timeout length).当我在本地测试图像时,我完全没有问题,但是当我在 lambda 中部署它时,它由于超时而失败(无论超时长度如何)。

Here's a slimmed down version of the lambda:这是 lambda 的精简版:

import pandas as pd
import json 
import pickle

def read_obj_from_s3(bucket, key):
    file_type = key.split('.')[-1]
    s3 = boto3.resource('s3')
    s3_bucket = s3.Bucket(bucket)
    s3_obj = s3_bucket.Object(key)
    file = s3_obj.get()['Body'].read() # here is where it hangs
    if file_type == 'json':
        return json.loads(file)
    return pickle.loads(file)

bucket = 'project-underdog-s3'

df = read_obj_from_s3('BUCKET_NAME', 'S3_LOCATION/file.json')

def lambda_handler(event, context):
    use_the_file(df)
    return json.dumps({
            'statusCode': 200,
                })

It seems the file always hangs at s3_obj.get()['Body'].read() .文件似乎总是挂在s3_obj.get()['Body'].read()

I have checked the Execution Role and it has AmazonS3FullAccess so permissions should be fine.我已经检查了执行角色,它有 AmazonS3FullAccess 所以权限应该没问题。

A number of similar questions were resolved as they were using a VPC.许多类似的问题在使用 VPC 时得到了解决。 To confirm, I'm not using a VPC.确认一下,我没有使用 VPC。 This is what is shown in the VPC section of the lambda:这是 lambda 的 VPC 部分中显示的内容:

No VPC configuration This function isn't connected to a VPC.无 VPC 配置 此 function 未连接到 VPC。

Appreciate any advice on where to investigate next.感谢有关下一步调查的任何建议。

The issue was memory.问题是 memory。 Once I increased the memory to 500Mb (from 128Mb) it worked.一旦我将 memory 增加到 500Mb(从 128Mb),它就起作用了。 The files were small but with the packages it was enough to push it over the edge.文件很小,但有了包裹就足以将其推到边缘。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM