Migrate from the AWS SDK for Java v1 to the AWS SDK for Java v2
Recipe ID
software.amazon.awssdk.v2migration.AwsSdkJavaV1ToV2Artifactorg.openrewrite.recipe:rewrite-third-partyThis recipe will apply changes required for migrating from the AWS SDK for Java v1 to the AWS SDK for Java v2.
Composite recipeawssdkApache 2.0
Add to your build
Get a download tokenSign in with GitHub or Google, and your token replaces YOUR_DOWNLOAD_TOKEN below. Free for open source recipes like this one.
~/.gradle/gradle.properties
codeGenomeUsername=you@example.com
codeGenomeToken=YOUR_DOWNLOAD_TOKEN
build.gradle.kts
plugins {
id("org.openrewrite.rewrite") version("latest.release")
}
rewrite {
activeRecipe("software.amazon.awssdk.v2migration.AwsSdkJavaV1ToV2")
}
repositories {
mavenCentral()
maven {
url = uri("https://artifacts.codegenomeproject.org/maven")
credentials {
username = providers.gradleProperty("codeGenomeUsername").get()
password = providers.gradleProperty("codeGenomeToken").get()
}
}
}
dependencies {
rewrite("org.openrewrite.recipe:rewrite-third-party:0.48.0")
}
Then run
./gradlew rewriteRunUsage
This recipe has no required configuration options. You’ll need the Moderne CLI configured before running the command below.
mod run . --recipe software.amazon.awssdk.v2migration.AwsSdkJavaV1ToV2If the recipe isn’t available locally, install it with:
mod config recipes jar install org.openrewrite.recipe:rewrite-third-party:RELEASEDefinition
This recipe runs the following recipes in order.
- Add AWS SDK for Java v2 S3 Transfer Manager dependency if needed
software.amazon.awssdk.v2migration.AddTransferManagerDependency - Add AWS SDK for Java v2 S3 Event Notification dependency if needed
software.amazon.awssdk.v2migration.AddS3EventNotificationDependency - Change v1 Maven/Gradle dependencies to v2
software.amazon.awssdk.v2migration.UpgradeSdkDependencies - Add imports and comments to unsupported S3 transforms.
software.amazon.awssdk.v2migration.S3AddImportsAndComments - S3 Event Notification method to v2
software.amazon.awssdk.v2migration.S3EventNotificationMethodToV2 - Change S3 types to v2.
software.amazon.awssdk.v2migration.S3TypesToV2 - V1 S3Object to V2
software.amazon.awssdk.v2migration.S3StreamingResponseToV2 - V1 S3 streaming requests to V2
software.amazon.awssdk.v2migration.S3StreamingRequestToV2 - V1 S3 non-streaming requests to V2
software.amazon.awssdk.v2migration.S3NonStreamingRequestToV2 - Change S3 methods to v2.
software.amazon.awssdk.v2migration.S3MethodsToV2 - Change S3EventNotification methods to v2.
software.amazon.awssdk.v2migration.S3EventNotificationMethodsToV2 - S3 POJOs to V2
software.amazon.awssdk.v2migration.S3PojoToV2 - Change S3 method constructors to fluent builder calls
software.amazon.awssdk.v2migration.S3MethodsConstructorToFluent - Convert v1 AmazonS3URI to v2 S3Uri
software.amazon.awssdk.v2migration.S3UriToV2 - Change v1 enum getters to v2
software.amazon.awssdk.v2migration.EnumGettersToV2 - Change SDK TransferManager types from v1 to v2
software.amazon.awssdk.v2migration.ChangeTransferManagerTypes - Change SDK S3EventNotification types from v1 to v2
software.amazon.awssdk.v2migration.ChangeS3EventNotificationTypes - Change AWS SDK for Java v1 types to v2 equivalents
software.amazon.awssdk.v2migration.ChangeSdkType - SDK Exceptions Methods to V2
software.amazon.awssdk.v2migration.SdkExceptionToV2 - Change SDK core types from v1 to v2
software.amazon.awssdk.v2migration.ChangeSdkCoreTypes - V1 client builder variations to builder()
software.amazon.awssdk.v2migration.V1BuilderVariationsToV2Builder - Change new objects creation to Builder pattern
software.amazon.awssdk.v2migration.NewClassToBuilderPattern - Transform 'new' expressions to static factory methods
software.amazon.awssdk.v2migration.NewClassToStaticFactory - V1 Getter to V2
software.amazon.awssdk.v2migration.V1GetterToV2 - Move HTTP settings from the ClientOverrideConfiguration to ApacheHttpClient for sync and NettyNioAsyncHttpClient for async
software.amazon.awssdk.v2migration.HttpSettingsToHttpClient - Wrap the region string provided on the SDK client builder with Region.of
software.amazon.awssdk.v2migration.WrapSdkClientBuilderRegionStr - V1 Enum Casing to V2
software.amazon.awssdk.v2migration.EnumCasingToV2 - Convert SdkBytes to ByteBuffer
software.amazon.awssdk.v2migration.SdkBytesToByteBuffer - Convert ByteBuffer to SdkBytes
software.amazon.awssdk.v2migration.ByteBufferToSdkBytes - Convert Date to Instant
software.amazon.awssdk.v2migration.DateToInstant - V1 S3 non-streaming requests to V2
software.amazon.awssdk.v2migration.S3NonStreamingRequestToV2Complex - V1 S3 PutObjectRequest, AmazonS3.putObject(PutObjectRequest), and TransferManager.upload(PutObjectRequest) to V2
software.amazon.awssdk.v2migration.S3PutObjectRequestToV2 - Convert V1 setters to V2 toBuilder setters
software.amazon.awssdk.v2migration.SettersToBuilderV2 - Add imports and comments to unsupported S3 transfer manager transforms.
software.amazon.awssdk.v2migration.S3TmAddComments - Change TransferManager simple methods to v2.
software.amazon.awssdk.v2migration.ChangeTransferManagerSimpleMethods - Transfer Manager Methods to V2
software.amazon.awssdk.v2migration.TransferManagerMethodsToV2
Data tables
Structured output this recipe can produce.
- Source files that had resultsSource files that were modified by the recipe run.
org.openrewrite.table.SourcesFileResults - Source files that had search resultsSearch results that were found during the recipe run.
org.openrewrite.table.SearchResults - Source files that errored on a recipeThe details of all errors produced by a recipe run.
org.openrewrite.table.SourcesFileErrors - Recipe performanceStatistics used in analyzing the performance of recipes.
org.openrewrite.table.RecipeRunStats