Skip to content

Commit

Permalink
Deprecate IMDSv1 calls for obtaining EC2 metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
zengyu714 committed Dec 23, 2022
1 parent 4c91629 commit 934e697
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
18 changes: 7 additions & 11 deletions aws/kinesis/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -256,19 +256,15 @@ std::string get_region(const aws::kinesis::core::Configuration& config) {
return config.region();
}

Aws::Internal::EC2MetadataClient ec2_md;
auto az = ec2_md.GetResource(
"/latest/meta-data/placement/availability-zone/");
auto regex = std::regex("^([a-z]+-[a-z]+-[0-9])[a-z]$",
std::regex::ECMAScript);
std::smatch m;
if (std::regex_match(az, m, regex)) {
return m.str(1);
Aws::Internal::EC2MetadataClient ec2_client;
Aws::String region = ec2_client.GetCurrentRegion();
if (region.empty()) {
LOG(error) << "Could not configure the region. It was not given in the "
<< "config and we were unable to retrieve it from EC2 metadata.";
throw 1;
}

LOG(error) << "Could not configure the region. It was not given in the "
<< "config and we were unable to retrieve it from EC2 metadata.";
throw 1;
return region;
}

std::pair<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,8 @@ private KinesisProducer getProducer(AWSCredentialsProvider provider, AWSCredenti
.setRegion("us-west-1")
.setRecordTtl(200)
.setMetricsUploadDelay(100)
.setRecordTtl(100);
.setRecordTtl(100)
.setLogLevel("warning");
if (provider != null) {
cfg.setCredentialsProvider(provider);
}
Expand Down

0 comments on commit 934e697

Please sign in to comment.