My Issue: I am trying to create an AWS CLI script using Python and the Boto3 library. I want the script to ask for inputs (username? programmatic access? attach to which Group? Change password on first login? etc.) and set up the user with those details.
My Attempt: I can create the user and give the user programmatic access or not. My problem lies with passing the selected Group ARN to the attach_group_policy PolicyARN='aws:aws:iam::aws:policy/xxxx
I feel a veriable suits here but cannot think how to do it. Hopefully my code below shows my problem better.
iam = boto3.resource('iam')
iam_keys = boto3.resource('iam')
group_list = boto3.client('iam')
attach_group = boto3.client('iam')
mail = raw_input("Please enter your e-mail address: ")
response = iam.create_user(UserName=mail)
prog = raw_input("Do you require programmatic access?(y/n): ")
if prog == "y":
iam_keys.create_access_key(UserName=mail)
print("Make sure awscli is installed on your machine")
elif prog == "n":
print("Console access only")
### it is this area downwards that things break/get confusing
list = group_list.list_groups(MaxItems=150) ### works
for "GroupName" in list: ### works
print(list) ### works; prints as large JSON, need to output just u' GroupName
float(input("Please pick a Group {}".format(attach)))
var = attach_group.attach_group_policy(GroupName=attach, PolicyArn='aws:aws:iam::aws:policy/xxxx') ### Broke; need to fill in ARN somehow after forward slash
print(response, prog)
I want the selected Policy (selected by typing exact name of Group) to attach to the user.
Any help is greatly appreciated, I have very little Python knowledge nad have been following https://boto3.amazonaws.com/v1/documentation/api/latest/index.html
Thank you.