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

Upgrade multilang to use AWS SDK v2 #5 #1390

Open
wants to merge 44 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
a8b70da
Upgrade NestedPropertyKey and NestedPropertyProcessor to AWS SDKv2
ethkatnic Aug 20, 2024
119ef42
Rewrite KCLSTSAssumeRoleCredentialsProvider to use AWS SDK v2
ethkatnic Aug 20, 2024
17f7d51
Remove v1 credential wrapper from daemon configuration
ethkatnic Aug 20, 2024
c8f642b
Upgrade ProviderPropertyValueDecoder to aws SDK v2
ethkatnic Aug 21, 2024
f83f8c8
Upgrade DefaultCredentialsProvider and AwsBasicCredentials to AWS SDK v2
ethkatnic Aug 21, 2024
e640277
Fix syntax error, update method header for new clazz param
ethkatnic Aug 21, 2024
4edccf4
Add region validation to region setting in NestedPropertyProcessor
ethkatnic Aug 21, 2024
8aa81dc
Remove unused old sdk version
ethkatnic Aug 21, 2024
f8eafb4
Add casting check for create() provider
ethkatnic Aug 22, 2024
6799c81
Simplify StsAssumeRoleCredentialsProvider logic
ethkatnic Aug 27, 2024
22c2a7c
Simplify syntax of StsAssumeRoleCredentialsProvider
ethkatnic Aug 27, 2024
444a4dd
Add https check
ethkatnic Aug 27, 2024
921781b
Simplify decoder logic for empty create constructor. Update documenta…
ethkatnic Aug 29, 2024
9b34218
Clean up unused changes
ethkatnic Aug 29, 2024
6deff85
Remove unused prefix
ethkatnic Aug 29, 2024
77a3440
Clean up legacy library names
ethkatnic Aug 29, 2024
1e708e1
Add tests to validate create() method providers and StsAssumeRoleCred…
ethkatnic Sep 4, 2024
892cc79
Add functionality to decoder for create(arg) providers and refactor p…
ethkatnic Sep 4, 2024
90d984b
Add method header for getClass helper
ethkatnic Sep 4, 2024
3923eb8
Rewrite credentials doc to be consistent with v2 changes
ethkatnic Sep 4, 2024
42a7768
Merge pull request #1 from ethkatnic/aws-sdk-v1-to-v2
ethkatnic Sep 4, 2024
4d5a399
Fix method header to remove unused param description
ethkatnic Sep 5, 2024
ac7d975
Specify sts provider path for conversion to kclStsProvider
ethkatnic Sep 5, 2024
f87bf83
Reorganize getValidCredentialsProviders to simplify calls
ethkatnic Sep 9, 2024
f91140b
Merge pull request #2 from ethkatnic/provider-decoder-improvements
ethkatnic Sep 10, 2024
f8d5750
Update comment references to AWS SDK v2
ethkatnic Sep 10, 2024
df0782d
Replace AWSCredentialProvider with AwsCredentialProvider to be consis…
ethkatnic Sep 10, 2024
88dc89e
Remove unused import and clean up helper processKey fn
ethkatnic Sep 10, 2024
95253af
Remove inline comment
ethkatnic Sep 10, 2024
0d890a2
Add testing for property key parsing. Update documentation for provid…
ethkatnic Sep 23, 2024
fa361ca
Merge pull request #6 from ethkatnic/multilang-naming-convention-change
ethkatnic Sep 23, 2024
a754364
KCLv3 merge
furq-aws Oct 31, 2024
2524ef8
Fix DDBLeaseManagementFactory constructor javadoc and remove deprecat…
lucienlu-aws Oct 31, 2024
67d5404
Merge from multilang-kclv3 branch: Add multi-lang support for new con…
furq-aws Nov 1, 2024
0ac22c7
Remove deprecated method and code review for Lucien's test changes
akidambisrinivasan Nov 1, 2024
a27c22d
Rename few classes and fields from review of multi-lang changes
akidambisrinivasan Nov 2, 2024
fa4bf5b
Add migration script
ethkatnic Nov 2, 2024
3c4771a
Add support for PITR,Tags and Deletion protection for WorkerMetrics a…
Nov 1, 2024
674344f
Remove glue transient dependency on sdkv1
ethkatnic Nov 2, 2024
0917cc9
Merge branch 'master' into multilang-sdk-upgrade
ethkatnic Nov 4, 2024
16ab7c8
Catch up to kclv3-off-master
ethkatnic Nov 4, 2024
c27744d
Update properties files with correct property name
ethkatnic Nov 4, 2024
210d61a
Improve logging for failed/successful credential creation
ethkatnic Nov 4, 2024
88ff519
Fix sts assume role credential provider logic
ethkatnic Nov 5, 2024
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
47 changes: 15 additions & 32 deletions amazon-kinesis-client-multilang/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,12 @@
<parent>
<artifactId>amazon-kinesis-client-pom</artifactId>
<groupId>software.amazon.kinesis</groupId>
<version>2.6.1-SNAPSHOT</version>
<version>3.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>amazon-kinesis-client-multilang</artifactId>

<properties>
<aws-java-sdk.version>1.12.668</aws-java-sdk.version>
</properties>

<dependencies>
<dependency>
<groupId>software.amazon.kinesis</groupId>
Expand All @@ -43,36 +39,10 @@
<version>${awssdk.version}</version>
</dependency>

<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-core</artifactId>
<version>${aws-java-sdk.version}</version>
<exclusions>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</exclusion>
<exclusion>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-cbor</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-sts</artifactId>
<version>${aws-java-sdk.version}</version>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.24</version>
<version>1.18.28</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -104,6 +74,12 @@
</dependency>

<!-- Test -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.11.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand All @@ -122,6 +98,13 @@
<version>1.3</version>
<scope>test</scope>
</dependency>
<!-- Using older version to be compatible with Java 8 -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>3.12.4</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@
* applicationName = PythonKCLSample
*
* # Users can change the credentials provider the KCL will use to retrieve credentials.
* # The DefaultAWSCredentialsProviderChain checks several other providers, which is
* # The DefaultCredentialsProvider checks several other providers, which is
* # described here:
* # http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/auth/DefaultAWSCredentialsProviderChain.html
* AWSCredentialsProvider = DefaultAWSCredentialsProviderChain
* # https://sdk.amazonaws.com/java/api/2.0.0-preview-11/software/amazon/awssdk/auth/credentials/DefaultCredentialsProvider.html
* AwsCredentialsProvider = DefaultCredentialsProvider
* </pre>
*/
@Slf4j
Expand Down Expand Up @@ -141,7 +141,7 @@ void configureLogging(
}
}

String propertiesFile(final MultiLangDaemonArguments arguments) {
String validateAndGetPropertiesFileName(final MultiLangDaemonArguments arguments) {
String propertiesFile = "";

if (CollectionUtils.isNotEmpty(arguments.parameters)) {
Expand Down Expand Up @@ -216,9 +216,9 @@ public static void main(final String[] args) {
MultiLangDaemonArguments arguments = new MultiLangDaemonArguments();
JCommander jCommander = daemon.buildJCommanderAndParseArgs(arguments, args);
try {
String propertiesFile = daemon.propertiesFile(arguments);
String propertiesFileName = daemon.validateAndGetPropertiesFileName(arguments);
daemon.configureLogging(arguments.logConfiguration);
MultiLangDaemonConfig config = daemon.buildMultiLangDaemonConfig(propertiesFile);
MultiLangDaemonConfig config = daemon.buildMultiLangDaemonConfig(propertiesFileName);

Scheduler scheduler = daemon.buildScheduler(config);
MultiLangRunner runner = new MultiLangRunner(scheduler);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
package software.amazon.kinesis.multilang;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.amazonaws.regions.Regions;
import com.google.common.base.CaseFormat;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import software.amazon.awssdk.regions.Region;

/**
* Key-Value pairs which may be nested in, and extracted from, a property value
Expand Down Expand Up @@ -73,8 +74,13 @@ void visit(final NestedPropertyProcessor processor, final String endpoint) {
* @see <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-regions-availability-zones.html#concepts-regions">Available Regions</a>
*/
ENDPOINT_REGION {
void visit(final NestedPropertyProcessor processor, final String region) {
processor.acceptEndpointRegion(Regions.fromName(region));
void visit(final NestedPropertyProcessor processor, final String regionName) {
List<Region> validRegions = Region.regions();
Region region = Region.of(regionName);
if (!validRegions.contains(region)) {
throw new IllegalArgumentException("Invalid region name: " + regionName);
}
processor.acceptEndpointRegion(region);
}
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
package software.amazon.kinesis.multilang;

import com.amazonaws.regions.Regions;
import software.amazon.awssdk.regions.Region;

/**
* Defines methods to process {@link NestedPropertyKey}s.
Expand All @@ -28,7 +28,7 @@ public interface NestedPropertyProcessor {
* (e.g., https://sns.us-west-1.amazonaws.com, sns.us-west-1.amazonaws.com)
* @param signingRegion the region to use for SigV4 signing of requests (e.g. us-west-1)
*
* @see #acceptEndpointRegion(Regions)
* @see #acceptEndpointRegion(Region)
* @see <a href="https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/client/builder/AwsClientBuilder.EndpointConfiguration.html">
* AwsClientBuilder.EndpointConfiguration</a>
*/
Expand All @@ -42,7 +42,7 @@ public interface NestedPropertyProcessor {
*
* @see #acceptEndpoint(String, String)
*/
void acceptEndpointRegion(Regions region);
void acceptEndpointRegion(Region region);

/**
* Set the external id, an optional field to designate who can assume an IAM role.
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package software.amazon.kinesis.multilang.auth;

import java.net.URI;
import java.util.Arrays;

import software.amazon.awssdk.auth.credentials.AwsCredentials;
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.sts.StsClient;
import software.amazon.awssdk.services.sts.StsClientBuilder;
import software.amazon.awssdk.services.sts.auth.StsAssumeRoleCredentialsProvider;
import software.amazon.awssdk.services.sts.model.AssumeRoleRequest;
import software.amazon.awssdk.services.sts.model.AssumeRoleRequest.Builder;
import software.amazon.kinesis.multilang.NestedPropertyKey;
import software.amazon.kinesis.multilang.NestedPropertyProcessor;

public class KclStsAssumeRoleCredentialsProvider implements AwsCredentialsProvider, NestedPropertyProcessor {
private final Builder assumeRoleRequestBuilder;
private final StsClientBuilder stsClientBuilder;
private final StsAssumeRoleCredentialsProvider stsAssumeRoleCredentialsProvider;

public KclStsAssumeRoleCredentialsProvider(String[] params) {
this(params[0], params[1], Arrays.copyOfRange(params, 2, params.length));
}

public KclStsAssumeRoleCredentialsProvider(String roleArn, String roleSessionName, String... params) {
this.assumeRoleRequestBuilder =
AssumeRoleRequest.builder().roleArn(roleArn).roleSessionName(roleSessionName);
this.stsClientBuilder = StsClient.builder();
NestedPropertyKey.parse(this, params);
this.stsAssumeRoleCredentialsProvider = StsAssumeRoleCredentialsProvider.builder()
.refreshRequest(assumeRoleRequestBuilder.build())
.asyncCredentialUpdateEnabled(true)
.stsClient(stsClientBuilder.build())
.build();
}

@Override
public AwsCredentials resolveCredentials() {
return stsAssumeRoleCredentialsProvider.resolveCredentials();
}

@Override
public void acceptEndpoint(String serviceEndpoint, String signingRegion) {
if (!serviceEndpoint.startsWith("http://") && !serviceEndpoint.startsWith("https://")) {
serviceEndpoint = "https://" + serviceEndpoint;
}
stsClientBuilder.endpointOverride(URI.create(serviceEndpoint));
stsClientBuilder.region(Region.of(signingRegion));
}

@Override
public void acceptEndpointRegion(Region region) {
stsClientBuilder.region(region);
}

@Override
public void acceptExternalId(String externalId) {
assumeRoleRequestBuilder.externalId(externalId);
}
}
Loading
Loading