-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlambda_function.py
More file actions
29 lines (22 loc) · 773 Bytes
/
Copy pathlambda_function.py
File metadata and controls
29 lines (22 loc) · 773 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import boto3
import string
import random
secrets_client = boto3.client('secretsmanager')
def generate_password(length=12):
characters = string.ascii_letters + string.digits + "!@#$%^&*"
return ''.join(random.choice(characters) for _ in range(length))
def lambda_handler(event, context):
secret_name = "MyApp/DBPassword"
# Get current secret value
current_secret = secrets_client.get_secret_value(SecretId=secret_name)
# Generate new password
new_password = generate_password()
# Update the secret with new password
secrets_client.put_secret_value(
SecretId=secret_name,
SecretString=f'{{"password": "{new_password}"}}'
)
return {
"status": "success",
"new_password": new_password
}