AWS Lambda Python Puzzle

I have an AWS Lambda function that is written in Python 3.8 and imports the following modules:

import ask_sdk_core.utils as ask_utils
import regex as re

I decided to include the package files for these modules in a Layer so that I could separate “their code” from “my code.” I ran the following at the command line:

md package\python\lib\python3.8\site-packages
cd package\python\lib\python3.8\site-packages
pip install -–target . ask_sdk_core 
pip install --target . regex

I zipped it all up into package.zip and uploaded it to the Layer, per these instructions: https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html. When I ran my test code it complained:

{
  "errorMessage": "Unable to import module 'lambda_function': No module named 'regex._regex'",
  "errorType": "Runtime.ImportModuleError"
}

I knew my Layer was configured properly because the ask_sdk_core module was found before the regex wasn’t. Somehow, I stumbled across this article: https://aws.amazon.com/premiumsupport/knowledge-center/lambda-python-package-compatible/. This was the solution.

So I navigated to https://pypi.org and searched for regex. Then clicked downloads. Then found the Python 3.8 version of the manylinux1_x86_64.whl file, which was called:

regex-2020.11.13-cp38-cp38-manylinux1_x86_64.whl

I unzipped this file to my package\python\lib\python3.8\site-packages folder. Zipped it all up, uploaded to a new version of my Layer, removed the old Layer from the Lambda function and added the new one.

This time my test code worked like a charm.

Thank you to the Alexa Community (https://alexacommunity.slack.com) for your unwavering support during this ordeal.