News Server

The new AWS SDK for Kotlin with Coroutines support

Read this post in other languages:
한국어, 简体中文

The new AWS SDK for Kotlin was announced at AWS re:Invent in December 2021. Using the SDK, you can build Kotlin applications that work with Amazon S3, Amazon EC2, DynamoDB, and more. The SDK is currently in preview and is expected to become stable soon.

The SDK was designed from the ground up to support the Kotlin language and its best practices, providing Kotlin developers with a familiar and idiomatic experience for interacting with AWS. The SDK leverages Kotlin coroutines for asynchronous implementation, and there are plans to make it compatible with Kotlin multiplatform projects.

To start using the new SDK in your Kotlin programs, you’ll need to add a corresponding dependency to your project. For instance, if we would like to communicate with DynamoDB, then the aws.sdk.kotlin:dynamodb module is required:

You can find the complete list of supported modules in the documentation for the AWS SDK.

After downloading the dependencies we can start using the API:

The program simply retrieves the list of tables and prints the table names into the standard output. In the example above, listTables is a suspending function, so the code is wrapped into a runBlocking call.

How about a slightly more complex example that demonstrates downloading every S3 object in a bucket to a local temporary directory, featuring paginated access, concurrent flows, and byte-streaming responses?

In the example above, you can see again the use of the suspending functions in the SDK: the getObject and writeToFile functions are all marked with the suspend keyword.

In the official documentation for the new AWS SDK for Kotlin, you can find detailed step-by-step instructions on how to get started. Also, you can find a number of interesting examples that demonstrate the API with a number of AWS services such as Amazon DynamoDB, S3, Rekognition, Amazon Simple Notification Service, and AWS Key Management Service.

The new AWS SDK for Kotlin is in active development and you can check out what features are planned in the roadmap. Try it now and let us know what you think!

Discover more