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
1 parent
f41026b
commit 9413a26
Showing
4 changed files
with
45 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import os | ||
from typing import Dict | ||
|
||
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 | ||
|
||
logger = Logger() | ||
|
||
KMS_KEY_ARN = os.getenv("KMS_KEY_ARN") | ||
encryption_provider = AwsEncryptionSdkProvider(keys=[KMS_KEY_ARN]) | ||
data_masker = DataMasking(provider=encryption_provider) | ||
|
||
|
||
def lambda_handler(event: Dict, context: LambdaContext) -> Dict: | ||
data = event.get("body") | ||
|
||
logger.info("Encrypting fields email, address.street, and company_address") | ||
|
||
encrypted = data_masker.encrypt(data=data, fields=["email", "address.street", "company_address"]) | ||
|
||
return {"payload_encrypted": encrypted} |
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 |
---|---|---|
@@ -1,17 +1,23 @@ | ||
import os | ||
from typing import Dict | ||
|
||
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 | ||
|
||
logger = Logger() | ||
|
||
KMS_KEY_ARN = os.getenv("KMS_KEY_ARN") | ||
encryption_provider = AwsEncryptionSdkProvider(keys=[KMS_KEY_ARN]) | ||
data_masker = DataMasking(provider=encryption_provider) | ||
|
||
def lambda_handler(event, context): | ||
|
||
data = event["body"] | ||
def lambda_handler(event: Dict, context: LambdaContext) -> Dict: | ||
data = event.get("body") | ||
|
||
encryption_provider = AwsEncryptionSdkProvider(keys=[KMS_KEY_ARN]) | ||
data_masker = DataMasking(provider=encryption_provider) | ||
logger.info("Encrypting fields email, address.street, and company_address") | ||
|
||
encrypted = data_masker.encrypt(data=data, fields=["email", "address.street", "company_address"]) | ||
|
||
data_masker.decrypt(data=encrypted, fields=["email", "address.street", "company_address"]) | ||
return {"payload_encrypted": encrypted} |
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