1

For security reasons I want to put some encrypted environmental variables in my lambda function, which includes pandas, numpy,psycopg2 and sklearn as extra python packages.

The function works smoothly but when I introduce the following code for the decrypting the variables it stops working:

import os
from base64 import b64decode

keys = {}
def get_variables(variable):
    encrypted = os.environ[f'{variable}']
    decrypted = boto3.client('kms').decrypt(CiphertextBlob=b64decode(encrypted))['Plaintext']
    keys[variable] = str(decrypted, 'utf-8') 

for variable in ['dbname','port','user','password','host']:
   get_variables(variable)

def lambda_handler(event,context):

   code
   result = keys['password']
   return result

Specifically, the part that is breaking everything is this line

result = keys['password']

The code is correct because I have tested it in another Lambda function (plus it is based on the example provided by lambda itself), and the error I get is the following:

/var/task/sklearn/externals/joblib/_multiprocessing_helpers.py:38: UserWarning: [Errno 38] Function not implemented.  joblib will operate in serial mode
  warnings.warn('%s.  joblib will operate in serial mode' % (e,))

I have no idea what to do for solving it.

Javier Lopez Tomas
  • 2,072
  • 3
  • 19
  • 41
  • Does the function not work? I did a search on your error and came across this on hackerrank: "Hi, This is just an ignorable warning and the program will work without it as well. It just means that one part of sklearn which typically parallizes/multi-threads some computation, will run serially instead." – Michael Brown May 14 '19 at 14:42
  • This question provides some links that explain what's going on and that essentially it is a matter of the lambda environment. https://stackoverflow.com/questions/55577358/how-should-i-treat-joblib-multiprocessing-in-an-aws-lambda-implementation – Michael Brown May 14 '19 at 14:45
  • It looks like someone provided a solution at the end of this GH issue https://github.com/joblib/joblib/issues/391#issuecomment-290618736 – Michael Brown May 14 '19 at 14:50
  • It does not work, I don't get any response but "Task timed out after 30.01 seconds". Yes, I have read the solution you have linked (thank you), but without the piece of code I have put here, sklearn works perfectly and I get no error at all, which is what is freaking me out. Also, I have to compile sklearn into a zip from a docker using a EC2 instance, so editing the code from sklearn through the terminal to modify that line would be very very painful – Javier Lopez Tomas May 14 '19 at 14:51

0 Answers0