AWS Lambda错误:调用AssumeRole操作时发生错误(AccessDenied):访问被拒绝

时间:2019-05-29 07:07:04

标签: amazon-web-services aws-lambda amazon-iam

我正在尝试从Prod帐户访问Dev帐户中的(列出)Lambda函数。以下是我遵循的步骤。 我在prod下创建了一个Lambda函数,并为其附加了一个角色,该角色有权承担角色。

enter image description here

但是我遇到了以下错误:

错误:

An error occurred (AccessDenied) when calling the AssumeRole operation: Access denied
Traceback (most recent call last):

产品帐户角色:

{
  "Version": "2012-10-17",
  "Statement": {
    "Effect": "Allow",
    "Action": "sts:AssumeRole",
    "Resource": "arn:aws:iam::**dev-account-number**:role/Dev*"
  }
}

开发人员帐户角色:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "AWS": "arn:aws:iam::prod-account-number:root"
      },
      "Action": "sts:AssumeRole",
      "Condition": {}
    }
  ]
}

代码:

import json
import boto3

def lambda_handler(event, context):
    sts_client = boto3.client('sts')

    assumed_role_object=sts_client.assume_role(
    RoleArn="arn:aws:iam::**dev-account-number**:role/Dev",RoleSessionName="AssumeRoleSession1")

    credentials=assumed_role_object['Credentials']
    print(credentials)


    s3_resource=boto3.resource(
        's3',
        aws_access_key_id=credentials['AccessKeyId'],
        aws_secret_access_key=credentials['SecretAccessKey'],
        aws_session_token=credentials['SessionToken'],
        ) 

在上一节中我还错过了什么其他步骤?

0 个答案:

没有答案