这个问题已经困扰了一个星期了。 老实说,我认为目前 Kinesis Firehose 中的 us-east-1 中存在一个错误。
至少他们会自动创建具有错误信任关系的角色。 这是默认创建的: (我到处都把userID改成了123456)
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "",
"Effect": "Allow",
"Principal": {
"Service": "firehose.amazonaws.com"
},
"Action": "sts:AssumeRole",
"Condition": {
"StringEquals": {
"sts:ExternalId": "123456"
}
}
}
]
}
当我尝试从我的帐户调用 Should_role 时,我总是得到:
botocore.exceptions.ClientError: An error occurred (AccessDenied) when calling the AssumeRole operation: User: arn:aws:iam::123456:user/fh is not authorized to perform: sts:AssumeRole on resource: arn:aws:iam::123456:role/firehose_delivery_role2
用户 fh 具有管理员访问策略。
相反,您需要使用以下实际有效的信任关系:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::123456:root"
},
"Action": "sts:AssumeRole"
}
]
}
但无论我做什么,当我尝试将任何东西放入 Firehose 时,我总是收到以下消息:
botocore.errorfactory.ResourceNotFoundException: An error occurred (ResourceNotFoundException) when calling the PutRecord operation: Stream test3 under account 123456 not found.
尝试使用管理员帐户访问它而不使用假设角色,得到了相同的结果。
我的 test3 流将数据传送到我的 elasticsearch。
有人可以创建新的elasticsearch、kinesis firehose 流并测试数据传输吗?最好来自 python/boto3。
这是代码示例。不要看变量名称;)
import boto3
import json
from datetime import datetime
import calendar
import random
import time
my_stream_name = 'python-stream'
kinesis_client = boto3.client('sts', aws_access_key_id='key', aws_secret_access_key='secret', region_name='us-east-1')
assumedRoleObject = kinesis_client.assume_role(
RoleArn="arn:aws:iam::123456:role/firehose_delivery_role3",
RoleSessionName="AssumeRoleSession1"
)
kinesis_session = boto3.Session(
aws_access_key_id=assumedRoleObject,
aws_secret_access_key=assumedRoleObject,
aws_session_token=assumedRoleObject)
client = kinesis_session.client('kinesis', region_name='us-east-1')
def put_to_stream(thing_id, property_value, property_timestamp):
payload = {
'prop': str(property_value),
'timestamp': str(property_timestamp),
'thing_id': thing_id
}
print payload
put_response = client.put_record(
StreamName='test3',
Data=json.dumps(payload),
PartitionKey=thing_id)
while True:
property_value = random.randint(40, 120)
property_timestamp = calendar.timegm(datetime.utcnow().timetuple())
thing_id = 'aa-bb'
put_to_stream(thing_id, property_value, property_timestamp)
# wait for 5 second
time.sleep(5)
最佳答案
Stream test3 under account 123456 not found
基本 AWS 功能中总是有可能存在其他用户没有注意到的错误,但这不太可能。
kinesis_session.client('kinesis', region_name='us-east-1')
这会为 Kinesis Data Streams 创建一个客户端,但您的帖子是关于 Kinesis Firehose 的。它们是不同的东西,Boto 使用不同的客户端。来自the docs:
client = boto3.client('firehose')
关于amazon-web-services - 从 Python 将数据流式传输到 AWS Kinesis Firehose 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49065384/