簡體   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