このスクリプトを実行してs3バケットへの依存性を収集し、それをラムダ展開パッケージに追加してみてください。
"""
This lambda function collects python pip dependencies, and uploads them to S3 bucket
as a single tar.gz file. Example input for Lambda event:
event = {
"prefix" : "myPackage",
"saveToS3Bucket" : "my-s3-bucket",
"saveToS3Key" : "package-jwt.tar.gz",
"requirements" : [ "cryptography==2.1.3",
"PyJWT==1.5.3" ]
}
Minimal Lambda execution role:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Stmt1507151548000",
"Effect": "Allow",
"Action": [
"s3:PutObject"
],
"Resource": [
"arn:aws:s3:::my-s3-bucket/package-jwt.tar.gz"
]
},
{
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": "*"
}
]
}
"""
from subprocess import check_output
import uuid
import boto3
DEBUG_OUT_FILE = "/tmp/debug.txt"
S3 = boto3.resource('s3')
def lambda_handler(event, context):
"""
"""
requirements = event.get('requirements', [])
prefix = event.get('prefix', 'myPackage')
saveToS3Bucket = event.get('saveToS3Bucket', None)
saveToS3Key = event.get('saveToS3Key', None)
location = "%s_%s" % (prefix, uuid.uuid4())
destinationPath = '/tmp/%s' % location
tarFileName = '/tmp/%s.tar.gz' % location
for req in requirements:
_exec(['pip', 'install', req, '-t', destinationPath])
_exec(['tar', 'czvf', tarFileName, destinationPath])
_persist_file_to_s3(tarFileName, saveToS3Bucket, saveToS3Key)
return 'done!'
def _exec(statements):
if statements and type(statements) == list:
with open(DEBUG_OUT_FILE, "a") as f:
try:
f.write("\n$ %s \n" % " ".join(statements))
rv = check_output(statements).decode("utf8")
f.write(rv)
print(rv)
except Exception as ex:
print(ex)
f.write(str(ex))
def _persist_file_to_s3(filePathToUpload, s3Bucket, s3Key):
if filePathToUpload and s3Bucket and s3Key:
S3.meta.client.upload_file(filePathToUpload, s3Bucket, s3Key)
ありがとうございます。私はリンクにpyodbcパッケージは表示されていませんが –
次に、Amazon Linuxマシンでそれを構築する必要があります: https://docs.aws.amazon.com/lambda/latest/dg/lambda-python -how-to-create-deployment-package.html – joarleymoraes