-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiam-user-creation.py
50 lines (40 loc) · 1.2 KB
/
iam-user-creation.py
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
import boto3
import random
import string
import os
iam = boto3.resource('iam')
iam_keys = boto3.resource('iam')
group_list = boto3.client('iam')
attach_group = boto3.client('iam')
grp = boto3.client('iam')
client = boto3.client('iam')
user = os.getenv('user')
response = iam.create_user(UserName=user)
print(response)
#get random pass
characters = string.acsii_letters + string.digits + string.punctuation
password = ''.join(random.coice(characters) for i in range(12))
print("random password is:", password)
response1 = client.create_login_profile(
UserName=user,
Password=password,
PasswordResetRequired=True
)
print(response1)
list = group_list.list_groups()
groups = list['Groups']
print(groups)
index = 1
for group in groups:
print("%d: %s" % (index, group["GroupName"]))
index +=1
group_option = int(input("Please pick a Group Number: "))
arn = groups[group_option-1]["Arn"]
print("You selected option %d: %s" % (option, arn))
var = "%s" % (arn)
var.split(":group/")[1]
group = groups[group_option-1]
group_name = group["GroupName"]
group_arn = group["Arn"]
final = grp.add_user_to_group(GroupName=group_name, UserName=user)
print("User has been addedto Group %s you selected" % (group_name))