【问题标题】:Issues with streaming data to AWS Kinesis Firehose from Python从 Python 将数据流式传输到 AWS Kinesis Firehose 的问题
【发布时间】:2018-08-10 10:44:26
【问题描述】:

这个问题已经困扰了一周了。 老实说,目前我认为这是 us-east-1 中 Kinesis Firehose 的某个错误。

至少他们会自动创建具有错误信任关系的角色。 以下是默认创建的内容: (我到处都将用户 ID 更改为 123456)

{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "",
"Effect": "Allow",
"Principal": {
"Service": "firehose.amazonaws.com"
},
"Action": "sts:AssumeRole",
"Condition": {
"StringEquals": {
"sts:ExternalId": "123456"
}
}
}
]
}

当我尝试从我的帐户调用假设角色时,我总是得到:

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"
}
]
}

但不管我做什么,当我尝试将任何东西放入消防软管时,我总是会收到以下消息:

botocore.errorfactory.ResourceNotFoundException: An error occurred (ResourceNotFoundException) when calling the PutRecord operation: Stream test3 under account 123456 not found.

尝试使用管理员帐户访问它并且不使用假设角色得到了相同的结果。

我的 test3 流向我的 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)

【问题讨论】:

    标签: amazon-web-services amazon-kinesis-firehose


    【解决方案1】:

    未找到帐户 123456 下的流 test3

    基本 AWS 功能中总是有可能存在其他用户没有注意到的错误,但这不太可能。

    kinesis_session.client('kinesis', region_name='us-east-1')

    这将为 Kinesis Data Streams 创建一个客户端,但您的帖子是关于 Kinesis Firehose 的。它们是不同的东西,Boto 使用不同的客户端。来自the docs

    client = boto3.client('firehose')
    

    【讨论】:

    • 解决了找不到流的问题。我想我对所有我没有注意到明显的信任错误配置太分心了。谢谢。
    • @urian - 信任关系没有问题。当您在控制台中创建角色时,您允许 Firehose 读取您的流。为了写入流,您需要另一个角色。您可以将它们组合起来(信任多个主体),但这通常不是一个好主意(首选细化权限,因为它们可以更容易地修改/撤销)。
    猜你喜欢
    • 2018-12-05
    • 2021-07-17
    • 1970-01-01
    • 2016-11-13
    • 2019-09-06
    • 2019-08-20
    • 2019-01-09
    • 2021-05-30
    • 1970-01-01
    相关资源
    最近更新 更多