Amazon web services en核心web sm模块错误-无服务器部署AWS Lambda

Amazon web services en核心web sm模块错误-无服务器部署AWS Lambda,amazon-web-services,configuration,aws-lambda,serverless-framework,spacy,Amazon Web Services,Configuration,Aws Lambda,Serverless Framework,Spacy,我在Python AWS Lambda中使用SpaCy的en-core web sm。我运行pip freeze>requirements.txt来获取requirements.txt文件中的所有依赖项。en core web sm==2.1.0是文件中的一行 当我尝试进行无服务器部署时,出现错误:从版本中找不到满足en core web sm==2.1.0要求的版本:无错误:找不到en core web sm==2.1.0的匹配发行版 尽管我没有使用Heroku,但我还是照做并添加了这一行ht

我在Python AWS Lambda中使用SpaCy的en-core web sm。我运行pip freeze>requirements.txt来获取requirements.txt文件中的所有依赖项。en core web sm==2.1.0是文件中的一行

当我尝试进行无服务器部署时,出现错误:从版本中找不到满足en core web sm==2.1.0要求的版本:无错误:找不到en core web sm==2.1.0的匹配发行版

尽管我没有使用Heroku,但我还是照做并添加了这一行https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.1.0/en_core_web_sm-2.1.0.tar.gzegg=en_core_web_sm==2.1.0 在my requirements.txt文件中,仅获取解压缩的大小必须小于262144000字节服务:AWSLambdaInternal;身份代码:400;错误代码:InvalidParameterValueException;请求ID:XxX XxX


如何将en web core sm连接到my Lambda?

利用模型作为库的独立组件的优势,将模型上传到S3存储桶中。在初始化spaCy之前,我从S3下载模型。这是通过以下方法实现的

def download_dir(dist, local, bucket):
    client = get_boto3_client('s3', lambda n: boto3.client('s3'))
    resource = get_boto3_client('s3r', lambda n: boto3.resource('s3'))

    paginator = client.get_paginator('list_objects')
    for result in paginator.paginate(Bucket=bucket, Delimiter='/', Prefix=dist):
        if result.get('CommonPrefixes') is not None:
            for subdir in result.get('CommonPrefixes'):
                download_dir(subdir.get('Prefix'), local, bucket)
        if result.get('Contents') is not None:
            for file in result.get('Contents'):

                if not os.path.exists(os.path.dirname(local + os.sep + file.get('Key'))):
                    os.makedirs(os.path.dirname(local + os.sep + file.get('Key')))
                dest_path = local + os.sep + file.get('Key')

                if not dest_path.endswith('/'):
                    resource.meta.client.download_file(bucket, file.get('Key'), dest_path)
使用spaCy的代码如下所示:

import spacy
if not os.path.isdir(f'/tmp/en_core_web_sm-2.0.0'):
       download_dir(lang, '/tmp', mapping_bucket)
spacy.util.set_data_path('/tmp')

nlp = spacy.load(f'/tmp/en_core_web_sm-2.0.0')
doc = nlp(spacy_input)
for token in doc:
    print(token.text, token.pos_, token.label_)

希望能帮助你。@ChandanGupta:我发现安装时出错了https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-1.2.0/en_core_web_sm-1.2.0.tar.gzegg=en-核心网络sm!当我将此添加到requirements.txt文件时,将重试。@Nagarajan Shanmuganathan,这个答案对您有帮助吗?我开始使用一个3P Lambda,它捆绑了SpaCy,因为我想要快速部署,避免了在S3上管理文件和引导的所有开销。get_boto3_客户端位从何而来?我得到错误:NameError:name'get\u boto3\u client'未定义。我试着从boto3导入,但没有成功