code: def encrypt(key, message):
      '''encrypt leverages KMS encrypt and base64-encode encrypted blob
  
          More info on KMS encrypt API:
          https://docs.aws.amazon.com/kms/latest/APIReference/API_encrypt.html
      '''
      try:
          ret = kms.encrypt(KeyId=key, Plaintext=message)
          encrypted_data = base64.encodestring(ret.get('CiphertextBlob'))
      except Exception as e:
          # returns http 500 back to user and log error details in Cloudwatch Logs
          raise Exception("Unable to encrypt data: ", e)
  
      return encrypted_data.decode(f encrypt(key, message):
      '''encrypt leverages KMS encrypt and base64-encode encrypted blob
  
          More info on KMS encrypt API:
          https://docs.aws.amazon.com/kms/latest/APIReference/API_encrypt.html
      '''
      try:
          ret = kms.encrypt(KeyId=key, Plaintext=message)
          encrypted_data = base64.encodestring(ret.get('CiphertextBlob'))
      except Exception as e:
          # returns http 500 back to user and log error details in Cloudwatch Logs
          raise Exception("Unable to encrypt data: ", e)
  
      return encrypted_data.decode()
docs: encrypt leverages KMS encrypt and base64-encode encrypted blob
  
          More info on KMS encrypt API:
          https://docs.aws.amazon.com/kms/latest/APIReference/API_encrypt.html