Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide credentials via configuration #38

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ You can build the project by running "maven package" and it will build amazon-ki

1. Make sure you create a delivery stream in AWS Console/CLI/SDK – See more details [here](http://docs.aws.amazon.com/firehose/latest/dev/basic-create.html) and configure destination.

2. Connector uses [DefaultAWSCredentialsProviderChain](http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/auth/DefaultAWSCredentialsProviderChain.html) for authenitication. It looks for credentials in following order - environment variable, java system properties, credentials profile file at default location ( (~/.aws/credentials), credentials delievered through Amazon EC2 container service, and instance profile credentails delivered through Amazon EC2 metadata service. Make sure user has at least permission to list streams/delivery stream, describe streams/delivery stream and put records for stream/delivery stream.
2. If you don't specify aws user key nor aws secret key then connector will use [DefaultAWSCredentialsProviderChain](http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/auth/DefaultAWSCredentialsProviderChain.html) for authenitication. It looks for credentials in following order - environment variable, java system properties, credentials profile file at default location ( (~/.aws/credentials), credentials delievered through Amazon EC2 container service, and instance profile credentails delivered through Amazon EC2 metadata service. Make sure user has at least permission to list streams/delivery stream, describe streams/delivery stream and put records for stream/delivery stream.

### Running a Connector

Expand All @@ -39,6 +39,8 @@ You can build the project by running "maven package" and it will build amazon-ki
| connector.class | Class for Amazon Kinesis Firehose Connector | com.amazon.kinesis.kafka.FirehoseSinkConnector |
| topics | Kafka topics from where you want to consume messages. It can be single topic or comma separated list of topics | - |
| region| Specify region of your Kinesis Firehose | - |
| awsKey | AWS user key.| - |
| awsSecret | AWS user secret key.| - |
| batch | Connector batches messages before sending to Kinesis Firehose (true/false) | true |
| batchSize | Number of messages to be batched together. Firehose accepts at max 500 messages in one batch. | 500 |
| batchSizeInBytes | Message size in bytes when batched together. Firehose accepts at max 4MB in one batch. | 3670016 |
Expand All @@ -49,7 +51,7 @@ You can build the project by running "maven package" and it will build amazon-ki

1. Make sure you create Kinesis stream in AWS Console/CLI/SDK – See more details [here](http://docs.aws.amazon.com/streams/latest/dev/learning-kinesis-module-one-create-stream.html).

2. Connector uses [DefaultAWSCredentialsProviderChain](http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/auth/DefaultAWSCredentialsProviderChain.html) for authenitication. It looks for credentials in following order - environment variable, java system properties, credentials profile file at default location ( (~/.aws/credentials), credentials delievered through Amazon EC2 container service, and instance profile credentails delivered through Amazon EC2 metadata service. Make sure user has at least permission to list streams/delivery stream, describe streams/delivery stream and put records for stream/delivery stream.
2. If you don't specify aws user key nor aws secret key then connector will use [DefaultAWSCredentialsProviderChain](http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/auth/DefaultAWSCredentialsProviderChain.html) for authenitication. It looks for credentials in following order - environment variable, java system properties, credentials profile file at default location ( (~/.aws/credentials), credentials delievered through Amazon EC2 container service, and instance profile credentails delivered through Amazon EC2 metadata service. Make sure user has at least permission to list streams/delivery stream, describe streams/delivery stream and put records for stream/delivery stream.

### Running a Connector

Expand All @@ -73,6 +75,8 @@ You can build the project by running "maven package" and it will build amazon-ki
| topics | Kafka topics from where you want to consume messages. It can be single topic or comma separated list of topics | - |
| region| Specify region of your Kinesis Firehose | - |
| streamName | Kinesis Stream Name.| - |
| awsKey | AWS user key.| - |
| awsSecret | AWS user secret key.| - |
| usePartitionAsHashKey | Using Kafka partition key as hash key for Kinesis streams. | false |
| maxBufferedTime | Maximum amount of time (milliseconds) a record may spend being buffered before it gets sent. Records may be sent sooner than this depending on the other buffering limits. Range: [100..... 9223372036854775807] | 15000 |
| maxConnections | Maximum number of connections to open to the backend. HTTP requests are sent in parallel over multiple connections. Range: [1...256]. | 24 |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ public class AmazonKinesisSinkConnector extends SinkConnector {

public static final String REGION = "region";

public static final String AWS_KEY = "awsKey";

public static final String AWS_SECRET = "awsSecret";

public static final String STREAM_NAME = "streamName";

public static final String MAX_BUFFERED_TIME = "maxBufferedTime";
Expand Down Expand Up @@ -80,6 +84,10 @@ public class AmazonKinesisSinkConnector extends SinkConnector {

private String sleepCycles;

private String awsKey;

private String awsSecret;

@Override
public void start(Map<String, String> props) {
region = props.get(REGION);
Expand All @@ -99,6 +107,8 @@ public void start(Map<String, String> props) {
outstandingRecordsThreshold = props.get(OUTSTANDING_RECORDS_THRESHOLD);
sleepPeriod = props.get(SLEEP_PERIOD);
sleepCycles = props.get(SLEEP_CYCLES);
awsKey = props.get(AWS_KEY);
awsSecret = props.get(AWS_SECRET);
}

@Override
Expand Down Expand Up @@ -198,6 +208,9 @@ public List<Map<String, String>> taskConfigs(int maxTasks) {
config.put(SLEEP_CYCLES, sleepCycles);
else
config.put(SLEEP_CYCLES, "10");

config.put(AWS_KEY, awsKey);
config.put(AWS_SECRET, awsSecret);

configs.add(config);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import java.util.HashMap;
import java.util.Map;

import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import org.apache.kafka.clients.consumer.OffsetAndMetadata;
import org.apache.kafka.common.TopicPartition;
import org.apache.kafka.connect.errors.DataException;
Expand All @@ -28,6 +31,10 @@ public class AmazonKinesisSinkTask extends SinkTask {

private String regionName;

private String awsKey;

private String awsSecret;

private int maxConnections;

private int rateLimit;
Expand Down Expand Up @@ -264,6 +271,10 @@ public void start(Map<String, String> props) {

sleepCycles = Integer.parseInt(props.get(AmazonKinesisSinkConnector.SLEEP_CYCLES));

awsKey = props.get(AmazonKinesisSinkConnector.AWS_KEY);

awsSecret = props.get(AmazonKinesisSinkConnector.AWS_SECRET);

if (!singleKinesisProducerPerPartition)
kinesisProducer = getKinesisProducer();

Expand Down Expand Up @@ -303,7 +314,7 @@ public void stop() {
private KinesisProducer getKinesisProducer() {
KinesisProducerConfiguration config = new KinesisProducerConfiguration();
config.setRegion(regionName);
config.setCredentialsProvider(new DefaultAWSCredentialsProviderChain());
config.setCredentialsProvider(getCredentialProvider(awsKey, awsSecret));
config.setMaxConnections(maxConnections);

config.setAggregationEnabled(aggregration);
Expand Down Expand Up @@ -340,4 +351,9 @@ private KinesisProducer getKinesisProducer() {

}

private AWSCredentialsProvider getCredentialProvider(String key, String secret) {
if(key != null && secret != null)
return new AWSStaticCredentialsProvider(new BasicAWSCredentials(key, secret));
else return new DefaultAWSCredentialsProviderChain();
}
}