This repository has been archived by the owner on Aug 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from ProntoPro/develop
Release 0.1.0
- Loading branch information
Showing
11 changed files
with
744 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,35 @@ | ||
import boto3 | ||
import json | ||
import singer | ||
|
||
def deliver(config, record): | ||
stream_name = config.get("stream_name") | ||
partition_key = config.get("partition_key", "id") | ||
aws_access_key_id = config.get("aws_access_key_id") | ||
aws_secret_access_key = config.get("aws_secret_access_key") | ||
region_name = config.get("region_name") | ||
|
||
client = boto3.client( | ||
'kinesis', | ||
aws_access_key_id=aws_access_key_id, | ||
aws_secret_access_key=aws_secret_access_key, | ||
region_name=region_name | ||
) | ||
|
||
response = client.put_record( | ||
StreamName=stream_name, | ||
Data=json.dumps(record).encode(), | ||
PartitionKey=record[partition_key] | ||
) | ||
|
||
def kinesis_setup_client(config): | ||
aws_access_key_id = config.get("aws_access_key_id") | ||
aws_secret_access_key = config.get("aws_secret_access_key") | ||
region_name = config.get("region_name", "eu-west-2") | ||
|
||
return boto3.client( | ||
'kinesis', | ||
aws_access_key_id=aws_access_key_id, | ||
aws_secret_access_key=aws_secret_access_key, | ||
region_name=region_name | ||
) | ||
|
||
|
||
def kinesis_deliver(client, stream_name, partition_key, records): | ||
|
||
if len(records) == 0: | ||
raise Exception("Record list is empty") | ||
|
||
if isinstance(records, dict): | ||
raise Exception("Single record given, array is required") | ||
|
||
encoded_records = map(lambda x: json.dumps(x), records) | ||
payload = ("\n".join(encoded_records) + "\n") | ||
|
||
response = client.put_record( | ||
StreamName=stream_name, | ||
Data=payload.encode(), | ||
PartitionKey=records[0][partition_key] | ||
) | ||
return response |
Oops, something went wrong.