Skip to content

Instantly share code, notes, and snippets.

@chloegrace94
Created October 2, 2018 15:14
Show Gist options
  • Save chloegrace94/3e5fe3371a1fc84804cca09d46585a9c to your computer and use it in GitHub Desktop.
Save chloegrace94/3e5fe3371a1fc84804cca09d46585a9c to your computer and use it in GitHub Desktop.
How to decrypt an AWS Lambda environment variable
import boto3 # AWS SDK for Python
import os
from base64 import b64decode
# Retrieve environment variables
encrypted_environment_variable_a = os.environ['a']
encrypted_environment_variable_b = os.environ['b']
# KMS Client
kms = boto3.client('kms')
# Decrypt encrypted environment variables
decrypted_variable_a = boto3.client('kms').decrypt(CiphertextBlob=b64decode(encrypted_environment_variable_a))['Plaintext'].decode('utf-8')
decrypted_variable_b = boto3.client('kms').decrypt(CiphertextBlob=b64decode(encrypted_environment_variable_b))['Plaintext'].decode('utf-8')
@hareesh0909
Copy link

Thanks mate !!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment