forked from aws-powertools/powertools-lambda-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
48 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from _future_ import annotations | ||
|
||
import os | ||
|
||
from aws_lambda_powertools import Logger | ||
from aws_lambda_powertools.utilities.data_masking import DataMasking | ||
from aws_lambda_powertools.utilities.data_masking.provider.kms.aws_encryption_sdk import ( | ||
AWSEncryptionSDKProvider, | ||
) | ||
from aws_lambda_powertools.utilities.typing import LambdaContext | ||
|
||
KMS_KEY_ARN_1 = os.getenv("KMS_KEY_ARN_1", "") | ||
KMS_KEY_ARN_2 = os.getenv("KMS_KEY_ARN_2", "") | ||
|
||
encryption_provider = AWSEncryptionSDKProvider(keys=[KMS_KEY_ARN_1, KMS_KEY_ARN_2]) | ||
data_masker = DataMasking(provider=encryption_provider) | ||
|
||
logger = Logger() | ||
|
||
|
||
@logger.inject_lambda_context | ||
def lambda_handler(event: dict, context: LambdaContext) -> dict: | ||
data: dict = event.get("body", {}) | ||
|
||
logger.info("Encrypting the whole object") | ||
|
||
encrypted = data_masker.encrypt(data) | ||
|
||
return {"body": encrypted} |