简体   繁体   中英

get aws_secret_access_key to store in ~/.boto

Im trying to store in ~/.boto file the user aws_access_key_id and aws_secret_access_key keys.

I'm already storing aws_access_key_id correctly, but now, I don't know how can I get aws_secret_access_key so I can store it in ~/.boto file.

Do you know how can I get aws_secret_access_key ?

import  os
import boto.iam.connection

username = "user"

conection = boto.iam.connect_to_region("us-east-1")
conection.create_access_key(username)
conection.create_access_key(username)

k = conection.get_all_access_keys(username)
ackey =  k['list_access_keys_response']['list_access_keys_result']['access_key_metadata'][0]['access_key_id']
# and how to return the aws_secret_access_key??

with open(os.path.expanduser("~/.boto"),"w") as f:
    f.write("[Credentials]")
    f.write("/n")
    f.write("aws_access_key_id" + ackey)
    f.write("/n")
    f.write("aws_secret_access_key" + ??)

The secret_access_key associated with AWS API credentials is returned via the API when the access key is created. You must store the key at that point because it is never returned by the IAM service again. If you change your code to be something like this, you can capture the secret key at key creation time.

conection = boto.iam.connect_to_region("us-east-1")
response = connection.create_access_key(username)
secret_access_key = response['create_access_key_response']['create_access_key_result']['access_key']['secret_access_key']

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM