• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer

Mister PKI

SSL Certificates * SSL Tools * Certificate Decoder

  • PKI Training
  • OpenSSL
  • Keytool
  • PKI Tools
    • Apereo CAS
    • SAML
    • OpenID Connect
  • Get expert help

AWS Lambda pyOpenSSL and cryptography

February 11, 2022 by Mister PKI Leave a Comment

The purpose of this article is to demonstrate AWS Lambda pyOpenssl and cryptography installation in an AWS Lambda function. AWS Lambda is a cost effective solution for running all kinds of different jobs in all kinds of different languages and programming stacks, including Python. Python code will run in AWS Lambda with a runtime provided by Lambda. Not to get off topic for the purpose of this article, but AWS is deprecating support for Python 2.x in the near future, so it is strongly recommended to proceed with Python 3.x.

One limitation or shortcoming if you will is the fact that not all python dependencies are readily available in the Lambda runtime. That point is what brings us to the purpose of this article which is to demonstrate how to install pyOpenSSL and cryptography libraries in the Python runtime in AWS Lambda.

AWS Lambda – Install pyOpenSSL

You may have received the following error message when importing your Lambda function into AWS:

"errorMessage": "Unable to import module 'lambda_function': No module named 'OpenSSL'"

This means that the pyOpenSSL module is not available in the Python runtime and must be added by you. Unfortunately this is not an easy process, but can be done nonetheless.

To install pyOpenSSL and cryptography in your AWS Lambda Python runtime, perform the following steps.

  1. Create a new EC2 instance using t2.micro and Amazon Linux 2.
  2. SSH into the machine with the generated private key from AWS.
  3. On the newly created EC2 instance, install python and virtualenv.
  4. Create a new python virtual environment by running virtualenv myvirtualenv
  5. Activate the virtualenv by running source myvirtualenv/bin/activate
  6. Install the pyOpenSSL and cryptography modules by running:
pip3 install \
--platform manylinux2010_x86_64 \
--implementation cp \
--python 3.7 \
--only-binary=:all: \
--upgrade \
--target myvirtualenv/lib/python3.7/site-packages/ \
cryptography pyOpenSSL
  1. Create a new directory for the lambda sandbox by running mkdir lambda-sandbox
  2. Copy the virtualenv python libraries to the sandbox.
cp -rf myvirtualenv/lib/python3.7/site-packages/* lambda-sandbox/
cp -rf myvirtualenv/lib64/python3.7/site-packages/* lambda-sandbox/
  1. Create a zip archive of the sandbox: cd lambda-sandbox; zip -r ../lambda-sanbox.zip
  2. Copy the zip archive of the sandbox from the EC2 instance to the root context of your AWS Lambda function project.
  3. Extract the archive into the project and build the Lambda function to be deployed via zip, docker, etc.
  4. After deploying your Lambda function, test it to make sure it’s working with the newly added pyOpenSSL and cryptography libraries. If it is, go ahead and delete the EC2 instance as it will no longer be needed.

Conclusion

This article has demonstrated how to install pyOpenSSL and cryptography libraries in AWS Lambda. If you have any questions, comments, or would like to see further examples of how to install additional dependencies or libraries in your Lambda runtime then leave us a comment. Visit our other articles for more how to’s in different programming languages and stacks.

python

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Popular Posts

PKCS12

openssl s_client

Keytool

Keytool list

ECDSA vs RSA

OpenSSL

PKCS7

Certificate Decoder

PKI for DevOps Engineers – Free Training Series

PKI for DevOps Training Hub

Lesson 1 – How TLS and PKI Work

Lesson 2 – Understanding X.509 Certificates

Lesson 3 – Certificate Chains Explained

Lesson 4 – Debug TLS with OpenSSL

Lesson 5 – Verify Certificate Chains

Lesson 6 – Creating CSRs with OpenSSL

Lesson 7 – Working with PKCS12 Certificates

Lesson 8 – Java Keystores and keytool

Lesson 9 – Certificate Expiration Monitoring

Lesson 10 – Automating Certificate Renewal

Lesson 11 – Common TLS Errors

Lesson 12 – PKI Architecture for DevOps

Recent Posts

  • Apache mod_auth_cas: Protect Web Applications with Apereo CAS and Docker
  • Apache mod_auth_mellon: Configure SAML SSO & Docker
  • Configure OpenID Connect (OIDC) in Apereo CAS 7.3 and 8
  • Certificate Ownership Is an Operating Model Problem, Not a Tooling Problem
  • OpenSSL dgst: Create Checksums and Verify Digital Signatures

Footer

  • Twitter
  • YouTube
Mister PKI

Practical security engineering for the systems that establish trust.

Learn OpenSSL Keytool Free training
Work together PKI consulting CAS consulting Sponsored contributions
Site About Support Mister PKI Cookie policy Search
© 2026 Mister PKI Secure systems. Clear guidance.