Aws lambda函数失败-Python

Aws lambda函数失败-Python,python,amazon-web-services,boto,boto3,Python,Amazon Web Services,Boto,Boto3,这是一个非常奇怪的问题,我陷入其中,如果有人能提供一些指导,我将非常感激。我正在尝试从web_token.py模块访问请求_url的值 当我只尝试在pycharm和print request_url上分别运行web_token.py时,它工作正常并生成url。我压缩了这两个文件并将其上载到lambda函数,但在测试它时,我得到一个错误“无法导入模块‘检索_帐户’:没有名为boto.sts的模块”。我甚至试着将web_token.py的代码放在retrieve_accounts.py中,但得到了相

这是一个非常奇怪的问题,我陷入其中,如果有人能提供一些指导,我将非常感激。我正在尝试从web_token.py模块访问请求_url的值

当我只尝试在pycharm和print request_url上分别运行web_token.py时,它工作正常并生成url。我压缩了这两个文件并将其上载到lambda函数,但在测试它时,我得到一个错误“无法导入模块‘检索_帐户’:没有名为boto.sts的模块”。我甚至试着将web_token.py的代码放在retrieve_accounts.py中,但得到了相同的错误。我确信我遗漏了一些非常基本的东西,看起来boto.sts在运行python脚本时没有被识别。有人能给我一些指导吗。谢谢大家!

检索_accounts.py

import boto3
import web_token

def get_account(event, context):

client = boto3.client('dynamodb')
NameID = "testname@org.com"
ManagerEmail = "test1@eorg.com"
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

AWS Lambda Python环境包括boto3(和botocore)。它们不包括较旧的boto(boto3的前身),因此导入失败


你可以在你的上传中包含boto,但如果你可以避免的话,最好不要将boto和boto3混用。使用一种或另一种,最好是boto3。

为什么要在那里混合boto和boto3?坚持使用boto3,比如导入boto3;client=bot3.client('sts')非常感谢您的指导,非常感谢。