이것은 내가 갇혀있는 매우 이상한 문제이며 누군가가 어떤 방향을 제시 할 수 있다면 정말 감사 할 것입니다. web_token.py 모듈에서 request_url 값에 액세스하려고합니다.Aws 람다 함수가 실패했습니다 - Python
pycharm을 통해 web_token.py를 별도로 실행하고 request_url을 인쇄하려고하면 URL이 제대로 작동하고 URL을 생성합니다. 나는이 두 파일을 모두 압축하여 람다 함수에 업로드하지만 테스트 할 때 "가져올 수 없습니다 'retrieve_accounts'모듈을 가져올 수 없습니다 : boto.sts라는 모듈이 없습니다." 나는 심지어 retrieve_accounts.py 안에 web_token.py 코드를 넣으려고했지만 같은 오류가 발생했습니다. 나는 python 스크립트를 실행하는 동안 boto.sts가 인식되지 않는 것처럼 보이는 매우 기본적인 것을 놓치고 있다고 확신합니다. 누군가가 약간의 안내를 해줄 수 있습니까? 고맙습니다!
retrieve_accounts.py
import boto3
import web_token
def get_account(event, context):
client = boto3.client('dynamodb')
NameID = "[email protected]"
ManagerEmail = "[email protected]"
response = client.scan(
TableName='Sandbox-Users',
ScanFilter={
'NameID': {
'AttributeValueList': [
{
'S': NameID,
},
],
'ComparisonOperator': 'EQ'
}
}
)
if response["Count"] > 0:
client = boto3.client('dynamodb')
response = client.get_item(
Key={
'NameID': {
'S': NameID,
},
'ManagerEmail': {
'S': ManagerEmail,
},
},
TableName='Sandbox-Users',
)
return web_token.request_url ----------->here
else:
response = client.put_item(
Item={
'NameID': {
'S': NameID,
},
'ManagerEmail': {
'S': ManagerEmail,
}
},
TableName='Sandbox-Users'
)
return "Create Account"
web_token.py
import httplib
import urllib, json
from boto.sts import STSConnection -------->Error here
sts_connection = STSConnection()
assumed_role_object = sts_connection.assume_role(
role_arn="arn:aws:iam::454084028794:role/AMPSandboxRole",
role_session_name="AssumeRoleSession"
)
# Step 3: Format resulting temporary credentials into JSON
json_string_with_temp_credentials = '{'
json_string_with_temp_credentials += '"sessionId":"' +
assumed_role_object.credentials.access_key + '",'
json_string_with_temp_credentials += '"sessionKey":"' +
assumed_role_object.credentials.secret_key + '",'
json_string_with_temp_credentials += '"sessionToken":"' +
assumed_role_object.credentials.session_token + '"'
json_string_with_temp_credentials += '}'
# Step 4. Make request to AWS federation endpoint to get sign-in token.
Construct the parameter string with the sign-in action request, a 12-hour session duration, and the JSON
document with temporary credentials as parameters.
request_parameters = "?Action=getSigninToken"
request_parameters += "&SessionDuration=43200"
request_parameters += "&Session=" +
urllib.quote_plus(json_string_with_temp_credentials)
request_url = "/federation" + request_parameters
conn = httplib.HTTPSConnection("signin.aws.amazon.com")
conn.request("GET", request_url)
r = conn.getresponse()
# Returns a JSON document with a single element named SigninToken.
signin_token = json.loads(r.read())
request_parameters = "?Action=login"
request_parameters += "&Issuer=sandbox.com"
request_parameters += "&Destination=" +
urllib.quote_plus("https://console.aws.amazon.com/")
request_parameters += "&SigninToken=" + signin_token["SigninToken"]
request_url = "https://signin.aws.amazon.com/federation" +
request_parameters
왜 boto와 boto3을 거기에 혼합하고 있습니까? boto3에'import boto3; client = boto3.client ('sts')' – ydaetskcoR