Skip to content

Failed to load psycopg in an uploaded function #152

@butla

Description

@butla

The function I've built and uploaded with lambda-uploader crashed with this error:
Unable to import module 'kinesis_worker': /var/task/psycopg2/_psycopg.so: undefined symbol: PyUnicodeUCS4_DecodeUTF8

My requirements.txt:

credstash==1.14.0
psycopg2==2.7.3.2

My lambda.json:

{
  "name": "kinesis-worker",
  "description": "Takes events off the Kinesis queue and puts them into the DB.",
  "region": "us-east-1",
  "runtime": "python3.6",
  "handler": "kinesis_worker.dump_records_to_db",
  "role": "arn:aws:iam::609235665469:role/test_worker_role",
  "ignore": [
    "asd"
  ],
  "subscription": {
    "kinesis": {
      "stream": "arn:aws:kinesis:us-east-1:609235665469:stream/test_stream",
      "batch_size": 500
    }
  }
}

The function works with AWS when I'm building with my own scripts (created them because of #151):

# build.sh
SCRIPT_LOCATION=$(realpath $(dirname $0))
echo Building a lambda package in $BUILD_DIR

VENV_DIR=${SCRIPT_LOCATION}/lambda_venv
if [ -d $VENV_DIR ]; then
    echo Removing old ${VENV_DIR}
    rm -rf $VENV_DIR
fi
python3.6 -m venv $VENV_DIR
${VENV_DIR}/bin/pip install -r ${SCRIPT_LOCATION}/requirements.txt

cp -r ${VENV_DIR}/lib/python3.6/site-packages ${SCRIPT_LOCATION}
BUILD_DIR=${SCRIPT_LOCATION}/lambda_build
if [ -d $BUILD_DIR ]; then
    echo Removing old ${BUILD_DIR}
    rm -rf $BUILD_DIR
fi
mv ${SCRIPT_LOCATION}/site-packages ${BUILD_DIR}

cp ${SCRIPT_LOCATION}/*.py ${BUILD_DIR}
find ${BUILD_DIR} -name __pycache__ | xargs rm -rf

LAMBDA_PACKAGE=lambda_package.zip
(
    cd $BUILD_DIR
    zip -r ${BUILD_DIR}/${LAMBDA_PACKAGE} .
    mv $LAMBDA_PACKAGE $SCRIPT_LOCATION
)

echo Built $LAMBDA_PACKAGE in $SCRIPT_LOCATION

# upload.sh
SCRIPT_LOCATION=$(realpath $(dirname $0))
LAMBDA_PACKAGE=${SCRIPT_LOCATION}/lambda_package.zip

aws lambda update-function-code \
    --function-name arn:aws:lambda:us-east-1:609235665469:function:kinesis_worker \
    --zip-file fileb://${LAMBDA_PACKAGE}

My OS is Kubuntu 17.10

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions