amazon-web-services - AWS lambda 在同一 aws 账户中担任角色以访问 S3
问题描述
我创建了一个角色来从 s3 存储桶中获取对象,如下所示:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "S3GetObjects",
"Effect": "Allow",
"Action": [
"s3:Get*"
],
"Resource": [
"arn:aws:s3:::cat-pics",
"arn:aws:s3:::cat-pics/"
]
}
]
}
接下来,创建了一个 lambda 函数来承担这个角色。为此,将以下语句添加到附加到 lambda 的基本 lambda 执行角色中:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "sts:AssumeRole",
"Resource": "arn:aws:iam::same-account-id:role/AssumeS3RoleDemo"
}
]
}
但是,下面的代码
import json
import boto3
def lambda_handler(event, context):
print("this test should be printed")
# create an STS client object that represents a live connection to the
# STS service
sts_client = boto3.client('sts')
# Call the assume_role method of the STSConnection object and pass the role
# ARN and a role session name.
assumed_role_object=sts_client.assume_role(
RoleArn="arn:aws:iam::same-account-id:role/AssumeS3RoleDemo",
RoleSessionName="AssumeRoleSession"
)
# From the response that contains the assumed role, get the temporary
# credentials that can be used to make subsequent API calls
credentials=assumed_role_object['Credentials']
print("credentials are")
print(credentials)
不起作用。我不断收到以下错误:
An error occurred (AccessDenied) when calling the AssumeRole operation: User: arn:aws:sts::same-account-id:assumed-role/lambda_basic_execution_new/AssumeRoleDemo is not authorized to perform: sts:AssumeRole on resource: arn:aws:iam::same-account-id:role/AssumeS3RoleDemo: ClientError
这里 AssumeRoleDemo 是 lambda 函数的名称,AssumeS3RoleDemo 是可以访问 S3 的角色名称。
是否可以在同一个帐户中担任角色?是这样,我在这里缺少什么步骤?请告诉我。
谢谢
解决方案
推荐阅读
- classification - ABBYY FineReader 分类
- java - 处理布尔数组的 int 输入时遇到问题
- c# - Dynamics CRM 2011 SyncWorkflowExecutionPlugin 找不到程序集
- javascript - 等待循环内的异步调用完成
- c++ - 如何使用文本文件中的数据将对象添加到向量中
- django - 如何在 django 中使用 id 作为外键?
- javascript - React TypeScript 如何遍历一个对象?
- ios - 从设置应用程序 ios 获取推送通知启用/禁用事件?
- node.js - 谷歌云存储对象上的 creategunzip()
- html - div 内 100% 宽度的输入与 div 重叠