Skip to content

Instantly share code, notes, and snippets.

@smd877
Created July 5, 2021 05:53
Show Gist options
  • Save smd877/cacf0859b223fd334dabaa3d074ceb2f to your computer and use it in GitHub Desktop.
Save smd877/cacf0859b223fd334dabaa3d074ceb2f to your computer and use it in GitHub Desktop.
AWS LambdaでKMS復号化を行うサンプル
import json
import boto3
import os
from base64 import b64decode
def lambda_handler(event, context):
ENCRYPTED = os.environ['key1']
DECRYPTED = boto3.client('kms').decrypt(
CiphertextBlob=b64decode(ENCRYPTED),
EncryptionContext={'LambdaFunctionName': os.environ['AWS_LAMBDA_FUNCTION_NAME']}
)['Plaintext'].decode('utf-8')
return {
'statusCode': 200,
'body': DECRYPTED
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment