繁体   English   中英

从Python向AWS Kinesis Firehose流数据的问题

[英]Issues with streaming data to AWS Kinesis Firehose from Python

这个问题困扰了一个星期。 老实说,我认为这是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"
}
}
}
]
}

当我尝试从我的帐户中调用authentic_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具有AdministratorAccess策略。

相反,您需要使用以下有效的信任关系:

{
"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.

尝试使用admin帐户访问并且没有exclude_role的情况也得到了相同的结果。

我的test3流将数据传递给我的elasticsearch。

有人可以创建新的elasticsearch,运动学流水线和测试数据传递吗? 理想情况下来自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)

找不到帐户123456下的流test3

AWS的基本功能中总是有一个漏洞未被其他用户注意到,但这是不可能的。

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

这为Kinesis Data Streams创建了一个客户端,但是您的帖子是关于Kinesis Firehose的 它们是不同的东西,并且Boto使用不同的客户端。 文档

client = boto3.client('firehose')

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM