-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsecrets_manager.py
More file actions
executable file
·53 lines (47 loc) · 1000 Bytes
/
secrets_manager.py
File metadata and controls
executable file
·53 lines (47 loc) · 1000 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python
import json
import boto3
import os
# List sedrets
region = os.environ['REGION']
secretsname = os.environ['SECRETS_NAME']
secclient = boto3.client('secretsmanager')
'''
require Action
{
"Sid": "NotSupportResourceLevelPermissions",
"Effect": "Allow",
"Action": [
"secretsmanager:ListSecrets",
"secretsmanager:ListSecretVersionIds"
],
"Resource": [
"*"
]
}
'''
def list():
response = client.list_secrets()
for secret in response['SecretList']:
print(secret['Name'])
'''
Get secret Value
require Action
{
"Sid": "NotSupportResourceLevelPermissions",
"Effect": "Allow",
"Action": [
"secretsmanager:GetSecretValue"
],
"Resource": [
"arn:aws:secretsmanager:<region>:<accountid>:secret:<secretname>-*"
]
}
'''
def get_secret(secret):
response = secclient.get_secret_value(
SecretId=secret
)
print(response['SecretString'])
# list()
get_secret(secretsname)