os
、context
或对象中是否有一个参数event
可以告诉您环境变量是否已加密,或者是否有任何变量已加密?
encrypted_db_password = os.environ['db_password']
try:
print 'attempting to decrypt'
db_password = boto3.client('kms').decrypt(CiphertextBlob=b64decode(encrypted_db_password)['Plaintext']
print 'successfully decrypted'
except:
print "Error decrypting, assuming a local environment"
db_password = encrypted_db_password
将尝试解密变量并在失败时使用明文,但不优雅且容易出错。有没有更好的办法?