-
Notifications
You must be signed in to change notification settings - Fork 332
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
Use sts to construct stream arn #463
Merged
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,8 @@ | |
#include <boost/format.hpp> | ||
#include <iomanip> | ||
|
||
#include <aws/core/utils/ARN.h> | ||
#include <aws/core/utils/StringUtils.h> | ||
#include <aws/kinesis/core/aggregator.h> | ||
#include <aws/kinesis/core/collector.h> | ||
#include <aws/kinesis/core/configuration.h> | ||
|
@@ -29,6 +31,12 @@ | |
#include <aws/kinesis/KinesisClient.h> | ||
#include <aws/metrics/metrics_manager.h> | ||
#include <aws/utils/processing_statistics_logger.h> | ||
#include <aws/sts/STSClient.h> | ||
#include <aws/sts/model/GetCallerIdentityRequest.h> | ||
#include <aws/sts/model/GetCallerIdentityResult.h> | ||
|
||
#include <aws/utils/logging.h> | ||
|
||
|
||
namespace aws { | ||
namespace kinesis { | ||
|
@@ -49,6 +57,7 @@ class Pipeline : boost::noncopyable { | |
Retrier::UserRecordCallback finish_user_record_cb) | ||
: stream_(std::move(stream)), | ||
region_(std::move(region)), | ||
stream_arn_(std::move(init_stream_arn(region_, stream_))), | ||
config_(std::move(config)), | ||
stats_logger_(stream_, config_->record_max_buffered_time()), | ||
executor_(std::move(executor)), | ||
|
@@ -60,6 +69,7 @@ class Pipeline : boost::noncopyable { | |
executor_, | ||
kinesis_client_, | ||
stream_, | ||
stream_arn_, | ||
metrics_manager_)), | ||
aggregator_( | ||
std::make_shared<Aggregator>( | ||
|
@@ -151,7 +161,7 @@ class Pipeline : boost::noncopyable { | |
} | ||
|
||
void send_put_records_request(const std::shared_ptr<PutRecordsRequest>& prr) { | ||
auto prc = std::make_shared<PutRecordsContext>(stream_, prr->items()); | ||
auto prc = std::make_shared<PutRecordsContext>(stream_, stream_arn_, prr->items()); | ||
prc->set_start(std::chrono::steady_clock::now()); | ||
kinesis_client_->PutRecordsAsync( | ||
prc->to_sdk_request(), | ||
|
@@ -190,8 +200,34 @@ class Pipeline : boost::noncopyable { | |
}); | ||
} | ||
|
||
std::string stream_; | ||
// Retrieve the account ID and partition from the STS service. | ||
static std::string init_stream_arn(const std::string ®ion, const std::string &stream_name) { | ||
Aws::STS::STSClient sts; | ||
Aws::STS::Model::GetCallerIdentityRequest request; | ||
auto outcome = sts.GetCallerIdentity(request); | ||
if (outcome.IsSuccess()) { | ||
auto result = outcome.GetResult(); | ||
Aws::Utils::ARN sts_arn(result.GetArn()); | ||
|
||
// Construct and return the Kinesis stream ARN. | ||
std::stringstream arn; | ||
arn << "arn:" << sts_arn.GetPartition() << ":kinesis:" << region << ":" << result.GetAccount() | ||
<< ":stream/" << stream_name; | ||
|
||
auto arn_str = arn.str(); | ||
LOG(info) << "StreamARN \"" << arn_str << "\" has been successfully configured, " | ||
<< "and will be used in requests including ListShards and PutRecords"; | ||
return arn_str; | ||
} | ||
|
||
LOG(warning) << "Failed to get StreamARN using STS GetCallerIdentity with exception: " | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should throw if this fails. that will avoid operating in dual-mode, and have all applications start using ARN from this version onwards. |
||
<< outcome.GetError().GetMessage().c_str(); | ||
return {}; | ||
} | ||
|
||
std::string region_; | ||
std::string stream_; | ||
std::string stream_arn_; | ||
std::shared_ptr<Configuration> config_; | ||
aws::utils::processing_statistics_logger stats_logger_; | ||
std::shared_ptr<aws::utils::Executor> executor_; | ||
|
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
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this stream arn format same for all regions? I thought we had some issues with arn format in some regions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good call out, we once had a problem with pod1, but I think the format is good for all public commercial regions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, we should still test to make sure this works in all partitions.