3 단계의 경우 프로젝트 루트에서 명령을 수행하는 데 몇 가지 문제가 있습니다.
sudo pip install MySQL-python -t /
오류:
예외: Traceback (most recent call last): File "/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg/pip/basecommand.py", line 122, in main status = self.run(options, args) File "/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg/pip/commands/install.py", line 311, in run os.path.join(options.target_dir, item) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 292, in move raise Error, "Destination path '%s' already exists" % real_dst 오류 : 대상 경로 '/MySQL_python-1.2.5-py2.7.egg-info/MySQL_python-1.2.5-py2.7.egg-info'가 이미 있습니다.
다음과 같은 람다 함수를 작성하게됩니다 (Mac에서 잘 작동 함).
import MySQLdb
def lambda_handler(event, context):
# Open database connection
db = MySQLdb.connect(...)
# prepare a cursor object using cursor() method
cursor = db.cursor()
sql = "SELECT * FROM Users"
try:
# Execute the SQL command
cursor.execute(sql)
# Fetch all the rows in a list of lists.
results = cursor.fetchall()
for row in results:
fname = row[0]
lname = row[1]
age = row[2]
sex = row[3]
income = row[4]
# Now print fetched result
print ("lname=%s" %(lname))
except:
print "Error: unable to fecth data"
# disconnect from server
db.close()
내가 한 일은 /Library/Python/2.7/site-packages로 이동하여 sudo pip install MySQL-python (-t /없이)을 수행했을 때 다운로드 한 MySQLdb 폴더 / 파일을 복사하는 것입니다. 내가 여기서 뭔가 잘못하고 있는지 확인) 내 람다 프로젝트에 콘텐츠를 압축 한 다음 lambda_function.py와 함께 콘텐츠를 압축하고 AWS Lambda에 업로드했습니다.
그런 다음 얻을 :
'lambda_function'모듈을 가져올 수 없음 : MySQLdb라는 모듈이 없습니다.
도움과 제안에 감사드립니다!
수정
sudo pip install MySQL-python -t / pathToProject 작업을 수행 할 수 있었지만 (주석의 도움에 감사드립니다) 이제 람다 함수를 실행할 때 이것을 얻습니다.
'lambda_function'모듈을 가져올 수 없음 : /var/task/_mysql.so : 유효하지 않은 ELF 헤더
나는 내가 리눅스 박스에서 작업한다면 (일부 사람들이 제안한 것처럼) 잘 작동 할 것이라는 것을 알고 있지만 OS X 박스에서 작동시킬 수 있는지 궁금합니다.
해결 방법
나는 그것을 프로덕션에 많이 사용했고 훌륭하게 작동합니다.
참조 페이지 https://stackoverflow.com/questions/35763380
'MySql' 카테고리의 다른 글
MySQL 날짜 비교 기능 (0) | 2020.11.11 |
---|---|
MySQL mysql 테이블의 두 번째 마지막 행 (0) | 2020.11.11 |
MySQL 테이블 데이터를 내보낼 때 phpMyAdmin에서 모든 외래 키를 비활성화하는 방법은 무엇입니까? (0) | 2020.11.11 |
MySQL 트리거를 호출하지 않고 mysql에서 쿼리 만들기 (트리거를 비활성화하는 방법) (0) | 2020.11.11 |
MySQL Python MySQLdb 연결을위한 SSH 터널 (0) | 2020.11.10 |
댓글