2016-12-21 1 views
3

IAM 역할이있는 EC2 인스턴스를 실행하면 해당 EC2 인스턴스에서 boto3을 사용할 수 있으며 boto3reads them automatically이므로 aws 액세스 및 비밀 키를 지정할 필요가 없습니다.boto3에서 access_key 및 secret_key를 가져 오는 방법이 있습니까?

>>> import boto3 
>>> s3 = boto3.resource("s3") 
>>> list(s3.buckets.all())[0] 
s3.Bucket(name='my-bucket-name') 

질문

boto3에서 액세스 키와 비밀 키를 얻을 수있는 방법이 있는지 궁금 해요? 예를 들어, 어떻게 print

답변

6

가 반드시 사용하여 표준 콘솔에 인쇄 할 수있다 (docs) :

from boto3 import Session 

session = Session() 
credentials = session.get_credentials() 
# Credentials are refreshable, so accessing your access key/secret key 
# separately can lead to a race condition. Use this to get an actual matched 
# set. 
current_credentials = credentials.get_frozen_credentials() 

# I would not recommend actually printing these. Generally unsafe. 
print(current_credentials.access_key) 
print(current_credentials.secret_key) 
print(current_credentials.token) 
이미 대답에 언급되지 않은 'get_frozen_credentials'방법의
+0

좋은 언급, 질문을 참조하십시오. – simon

+0

의심 : '세션'에 자격 증명을 전달하지 않고 반환하는 자격 증명을 'boto3'이 어떻게 알 수 있습니까? 또는 계정에서 반환해야하는 자격 증명이 있습니까? –

관련 문제