-
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.
changing SNS notification to include user object
- Loading branch information
Brad Duncan
committed
Feb 26, 2024
1 parent
c22f04c
commit 60b6ba6
Showing
5 changed files
with
72 additions
and
46 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
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,23 +1,25 @@ | ||
def write_deleted_users_to_s3(s3_client, deleted_users, bucket_name=None, s3_key=None): | ||
import json | ||
|
||
def write_deleted_users_to_s3(s3_client, deleted_users_info, bucket_name=None, s3_key=None): | ||
""" | ||
Writes the list of deleted users to a file in an S3 bucket. Skips writing if | ||
Writes the list of deleted user objects to a file in an S3 bucket in JSON format. Skips writing if | ||
bucket_name or s3_key is not provided. | ||
:param s3_client: Boto3 S3 client | ||
:param deleted_users: List of usernames that were deleted | ||
:param deleted_users_info: List of dictionaries containing user attributes | ||
:param bucket_name: The name of the S3 bucket where the file will be stored, optional | ||
:param s3_key: The S3 key (file path within the bucket) for the file, optional | ||
""" | ||
if not bucket_name or not s3_key: | ||
print("Skipping writing to S3 as either bucket_name or s3_key has not been set...") | ||
return | ||
|
||
# Convert the list of deleted users to a string, one username per line | ||
deleted_users_str = "\n".join(deleted_users) | ||
# Convert the list of deleted user objects to a JSON string | ||
deleted_users_json = json.dumps(deleted_users_info, indent=2) | ||
|
||
try: | ||
# Proceed to write the string to a file in S3 | ||
s3_client.put_object(Bucket=bucket_name, Key=s3_key, Body=deleted_users_str) | ||
# Proceed to write the JSON string to a file in S3 | ||
s3_client.put_object(Bucket=bucket_name, Key=s3_key, Body=deleted_users_json) | ||
print(f"Successfully wrote deleted users to {s3_key} in bucket {bucket_name}.") | ||
except Exception as e: | ||
print(f"Failed to write deleted users to S3: {e}") | ||
print(f"Failed to write deleted users to S3: {e}") |
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