![](/img/trans.png)
[英]downloading files from s3 bucket in amazon ec2 to local drive in windows 7
[英]How do I transfer a file from a AWS EC2 Amazon Linux Virtual Env to local (windows)?
我正在嘗試在 Python Lambda function 上使用 Sklearn。 由於 Sklearn 不是原生的,我需要在一個層中上傳庫及其依賴項。 一個這樣的依賴項 Numpy 比我可以上傳的要大,但幸運的是,AWS 已經提供了 Scipy、Numpy 層(AWSLambda-Python38-SciPy) I thought I need to create a layer with the remaining libraries and use both layers on my lambda function, Thus, I've created a layer with the libraries (joblib, threadpoolctl, scikit-learn and sklearn) on my windows, uploaded it and called the function。 這沒有用。 谷歌媽媽告訴我這是由於兼容性問題(windows-linux)¹。
{
"errorMessage": "Unable to import module 'lambda_function': cannot import name 'WinDLL' from 'ctypes' (/var/lang/lib/python3.8/ctypes/__init__.py)",
"errorType": "Runtime.ImportModuleError"
}
最后,我決定使用 Linux 實例,安裝 Python,其余庫然后上傳 Lambda 層。 我得到了一個“Amazon Linux AMI 2018.03.0 (HVM), SSD Volume Type”並執行了下面描述的步驟²(請善待 Linux 新手):
在我的 windows cmd
cd C:/path_to_aws.pem
ssh -i "file.pem" ec2-user@ec2-x.region.compute.amazonaws.com
sudo yum update
sudo su
yum install openssl-devel
yum install libffi-devel
yum groupinstall "Development Tools"
wget https://www.python.org/ftp/python/3.8.3/Python-3.8.3.tgz
tar -xf Python-3.8.3.tgz
cd Python-3.8.3
sudo su
./configure --enable-optimizations
nproc
make -j 1
sudo make altinstall
exit
curl -O https://bootstrap.pypa.io/get-pip.py
python3.8 get-pip.py
sudo su
python3.8 -m venv biblio/env
source ~/biblio/env/bin/activate
pip install pip --upgrade
pip install joblib
pip install threadpoolctl
pip install scikit-learn
pip install sklearn
zip -r python38_lib.zip /biblio
ISSUE:現在我已將庫安裝在 Linux 機器上,但是如何從本地環境將它安裝到我的計算機上? 如果它在實例上(環境外部)³,我知道如何獲取它:
scp -i " file.pem " ec2-user@ec2-x.region.compute.amazonaws.com:/path/file.zip C:/
如果您能幫我解決最初的問題,即在 Lambda 上運行 Sklearn,使用更短且無痛的解決方案:<3,否則。 你能幫我得到圖書館嗎?zip 文件到我的窗口?
非常感謝你。
¹ 無法導入模塊“lambda_function”:無法從“ctypes”導入名稱“WinDLL”(/var/lang/lib/python3.7/ctypes/__init__.py
² https://aws.amazon.com/pt/premiumsupport/knowledge-center/ec2-linux-python3-boto3/
³ https://medium.com/@dearsikandarkhan/files-copying-between-aws-ec2-and-local-d07ed205eefa
使用無服務器框架更容易構建 lambda 層。
# serverless.yml
service: serverless-example
plugins:
- serverless-python-requirements
custom:
pythonRequirements:
dockerizePip: non-linux
layer: true
provider:
name: aws
runtime: python3.8
stage: dev
region: us-east-1
profile: dummy
functions:
dummy:
handler: dummy.handler
# requirements.txt
joblib==0.16.0
threadpoolctl==2.1.0
scikit-learn==0.23.1
只需執行sls package -p pkg
,然后名為pythonRequirements.zip
的層 zip 將位於pkg
目錄中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.