AWS Developer Tools Blog

Announcing new AWS SDK for Swift alpha release

We’re excited to announce the alpha release of the new AWS SDK for Swift. Since 2010, AWS Mobile has provided customers with an iOS SDK, written in Objective C. While this SDK has served the iOS community for over a decade, the Swift community has grown in size and expanded to other platforms such as Linux, macOS, Windows, tvOS, watchOS, etc. AWS customers developing in Swift have asked for a native Swift SDK so they can use the language constructs they are used to. Additionally, customers new to Swift and running Swift server side want an SDK that behaves similarly to SDKs they have used in other language environments. With this alpha release, customers can try clients for all of the supported AWS services and provide feedback on ergonomics and usability.

Before we get into the details, it would be remiss of us not to acknowledge the enormous amount of work the community has put in to maintaining not one but two Swift AWS SDKs. On behalf of AWS, I’d like to thank all the maintainers and contributors to the Soto SDK and the AWS Smoke SDK. The AWS Smoke SDK was developed by the Amazon Prime Video Team and will be migrating to the new AWS SDK for Swift. Simon Pilkington, the lead maintainer of the AWS Smoke SDK and a Senior Software Engineer on the Amazon Prime Video Team, tried out the new AWS SDK for Swift and said “Using the Swift programming language has already given our team high developer velocity and strong compiler guarantees that eliminate common programming bugs before they hit production. By providing high quality, best-in-class clients — with strong DNA from previous development — out of the box and fully supported, this new AWS Swift SDK will allow us to focus on our business logic and go even faster.”

Our primary design goal for this SDK is to provide platform-agnostic idiomatic Swift interfaces to all supported AWS Service APIs and provide new AWS service APIs when they launch. Similar to other recently launched AWS SDKs, we used the Smithy toolchain and service models to build the new open source AWS SDK for Swift. In addition to enabling the use of new services on Day 1, this SDK contains features to create greater reliability and consistency in the developer experience. It already includes AWS standard retry logic and consistent credential provider support similar to other AWS SDKs.

The AWS SDK for Swift alpha release we are launching today allows you to build clients for any of supported AWS Service. Some service clients require additional modification from the SDK team and we’re working to identify and implement these as quickly as possible. We are releasing the alpha version of the SDK to get your feedback early and incorporate your input into the design and implementation of this SDK. We are sharing our roadmap, which outlines the plan for adding features and customizations for specific AWS services to improve functionality. We would love to hear your thoughts on what features and services are most important to you via GitHub Issues and Discussions. As the SDK approaches its General Availability launch, we will provide documentation for migrating from the iOS SDK, the Smoke SDK, or the Soto SDK to the new SDK. We will support the SDK following our standard maintenance policy at the GA launch.

Without further ado, let’s see the SDK in action!

Getting Started with the SDK

During the alpha, you can consume the SDK via tags using the Swift Package Manager.

Here’s an example of how to get started with the new AWS SDK for Swift, using Amazon CognitoIdentity to perform a common operation. This example assumes you already have the Swift toolchain or Xcode 12.5+ installed.

As an example, we will walk you through how you can use Amazon CognitoIdentity as a dependency in the steps below. To use it, we will create a test project called “TestCognitoSdk”.

mkdir TestCognitoSdk
cd TestCognitoSdk
swift package init --type executable
xed .

Once Xcode is open, open Package.swift. Update the file to mirror the following based on the version of Swift you are using.

For Swift 5.5+ users:

// swift-tools-version:5.5
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
    name: "TestCognitoSdk",
    platforms: [.macOS("12"), .iOS("15")],
    dependencies: [
        .package(name: "AWSSwiftSDK", url: "https://github.com/awslabs/aws-sdk-swift", from: "0.0.8"),
    ],
    targets: [
        // Targets are the basic building blocks of a package. A target can define a module or a test suite.
        // Targets can depend on other targets in this package, and on products in packages this package depends on.
        .executableTarget(
            name: "TestCognitoSdk",
            dependencies: [.product(name: "CognitoIdentity", package: "AWSSwiftSDK")]),
        .testTarget(
            name: "TestCognitoSdkTests",
            dependencies: ["TestCognitoSdk"]),
    ]
)

For Swift <5.5 users:

// swift-tools-version:5.4
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
    name: "TestCognitoSdk",
    platforms: [.macOS(.v10_15), .iOS(.v13)],
    dependencies: [
        .package(name: "AWSSwiftSDK", url: "https://github.com/awslabs/aws-sdk-swift", from: "0.0.8"),
    ],
    targets: [
        // Targets are the basic building blocks of a package. A target can define a module or a test suite.
        // Targets can depend on other targets in this package, and on products in packages this package depends on.
        .target(
            name: "TestCognitoSdk",
            dependencies: [.product(name: "CognitoIdentity", package: "AWSSwiftSDK")]),
        .testTarget(
            name: "TestCognitoSdkTests",
            dependencies: ["TestCognitoSdk"]),
    ]
)

In your main.swift you can now drop in the one of the following snippets below depending on which platform you are running on and which version of Swift.

// For Swift 5.5+ users
import CognitoIdentity

func createIdentityPool() async throws -> CreateIdentityPoolOutputResponse {
    let cognitoIdentityClient = try CognitoIdentityClient(region: "us-east-1")
    let cognitoInputCall = CreateIdentityPoolInput(developerProviderName: "com.amazonaws.mytestapplication",
                                                    identityPoolName: "identityPoolMadeWithSwiftSDK")
    
    let result = try await cognitoIdentityClient.createIdentityPool(input: cognitoInputCall)
    return result
}
//For Swift <5.5
import CognitoIdentity

do {
    let cognitoIdentityClient = try CognitoIdentityClient(region: "us-east-1")
    let cognitoInputCall = CreateIdentityPoolInput(developerProviderName: "com.amazonaws.mytestapplication",
                                                identityPoolName: "identityPoolMadeWithSwiftSDK")
    
    cognitoIdentityClient.createIdentityPool(input: cognitoInputCall) { result in 
        switch(result) {
        case .success(let output):
            print("\(output)")
        case .failure(let error):
            print("\(error)")
            
        }
    }
} catch let err {
    print(err)
}

As a result, you should be able to:

1. Log into your AWS console, go to us-east-1
2. Click on Cognito
3. click on Cognito Identity Pools
4. Verify that you see the newly created identity pool name: identityPoolMadeWithSwiftSDK

If you’ve made it this far… Congrats!?

What’s next? Try some other calls? Help us better understand what you think the most critical features are next. Run into any bugs? Open a Github issue and let us know.

Contributing to the SDK’s development

Make sure to check out the contributing guide to get the latest information. Here’s how you can help and provide feedback:

  • Try out the SDK and let us know what to improve. For the services the SDK supports, let us know if you run into any issues by submitting a GitHub Issue or starting a GitHub Discussion. Also, be sure to add your comments and “+1”s to GitHub Issues that have already been submitted to help us prioritize and plan effectively.
  • Report defects. Inevitably, we expect there to be bugs in this alpha release. If you find one, let us know by submitting a GitHub Issue.
  • Review the docs. The guide content is at a very early stage and more will be coming soon but it is essential the SDK docs are clear, accurate and up to date so everyone can successfully use the SDK. If you find an issue with the documentation, open an issue, or even better, submit a PR.
  • Request for Comments (RFCs). We are adding RFCs to the repo to propose major changes to the SDK. We will continually add more as we develop the SDK. Please review them, let us know what you think, and feel free to add your own!
  • Help us prioritize high level libraries. Beyond the core SDK, high level libraries built on top of the SDK (like the S3 Encryption Client or the DynamoDB Mapper) make some AWS services easier to use. Let us know which libraries are most important to you via a Github Discussion.

The SDK’s Public Roadmap

The AWS SDK for Swift currently provides support for retries and credential providers and will be adding more features like pagination and waiters. You can find the complete list of the AWS services the SDK currently supports in our GitHub repository. You can follow our plans to add support for features and service customizations by reviewing our public roadmap on GitHub. The purpose of the roadmap is to keep the community informed about what’s coming. We will keep this roadmap up to date with the team’s progress. Please add a “+1” to features most important to you. Your votes will help us prioritize our roadmap.

Give it a Try!

The getting started guide is a great place to start using the SDK. Check it out and let us know what do you think!

We’re Hiring

The AWS SDK for Swift team is hiring. If you’d like to join, please review the open positions on our team.

Authors

Nicki Stone: Nicki has worked at AWS since 2018, and most recently helped build Amplify Predictions for iOS prior to working on the AWS SDK for Swift.