嗨,我从昨天开始就有这个奇怪的问题。我有一个python模块web\u令牌。py当我尝试在pycharm上手动运行它并打印request\u url时,它工作完全正常,并输出请求的url。但是当我压缩我的web_令牌时。py和fetch_帐户。py一起上传到lambda函数,它给了我以下错误-
来自的代码段
import boto3
import web_token
def get_account(event, context):
client = boto3.client('dynamodb')
NameID = "test@orgz.com"
ManagerEmail = "test1@orgaz.com"
response = client.scan(
TableName='Sandbox-Users',
ScanFilter={
'NameID': {
'AttributeValueList': [
{
'S': NameID,
},
],
'ComparisonOperator': 'EQ'
}
}
)
return web_token.request_url
import httplib
import urllib, json
import boto3
client = boto3.client('sts')
assumed_role_object = client.assume_role(
RoleArn="arn:aws:iam::4540XXXXXXXX:role/AMPSandboxRole",
RoleSessionName="AssumeRoleSession"
)
json_string_with_temp_credentials = '{'
json_string_with_temp_credentials += '"sessionId":"' + assumed_role_object.get("Credentials").get("AccessKeyId") + '",'
json_string_with_temp_credentials += '"sessionKey":"' + assumed_role_object.get("Credentials").get("SecretAccessKey") + '",'
json_string_with_temp_credentials += '"sessionToken":"' + assumed_role_object.get("Credentials").get("SessionToken") + '"'
json_string_with_temp_credentials += '}'
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()
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
更新:
我有两个策略附加到sandbox-amp\u sandbox-dev角色-
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"sqs:SendMessage",
"sqs:SendMessageBatch"
],
"Resource": "arn:aws:sqs:*:131703196249:org-logging-prod",
"Effect": "Allow"
},
{
"Action": [
"ec2:DescribeInstances",
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": "*",
"Effect": "Allow"
},
{
"Effect": "Allow",
"Action": "s3:*",
"Resource": [
"arn:aws:s3:::em-log-intake-us-east-1-prod/*",
"arn:aws:s3:::em-log-intake-us-west-2-prod/*"
]
}
]
}
sandbox-amp_sandbox-policy-dev[在5398XXXXXXX中]
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "",
"Effect": "Allow",
"Action": "dynamodb:*",
"Resource": "arn:aws:dynamodb:*:*:*"
}
]
}
更新2.0
以上保单来自我的账号5398XXXXXXX。我在4540XXXXXXXX账户AMPSandboxRole中有以下角色,在此角色下我有以下政策
假设角色[在4540XXXXXXXX中]
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Resource": "arn:aws:iam::*:role/AMPSandboxRole",
"Action": "sts:AssumeRole"
}
]
}
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"organizations:Describe*",
"organizations:List*",
"organizations:CreateAccount",
"organizations:MoveAccount"
],
"Resource": "*"
},
{
"Effect": "Allow",
"Action": [
"organizations:MoveAccount"
],
"Resource": "arn:aws:organizations::454084028794:root/o-eyec2h6qr0/r-ekzh"
},
{
"Effect": "Allow",
"Action": [
"organizations:*"
],
"Resource": "arn:aws:organizations::45xxxxxxxxxx:ou/o-eyec2h6qr0/ou-ekzh-x2xcsupl"
}
]
}
更新3.0
45xxxxxxxxx中的信任关系
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::53xxxxxxxxxx:root"
},
"Action": "sts:AssumeRole"
}
]
}