Home Cloud Computing New – Add Your Swift Packages to AWS CodeArtifact

New – Add Your Swift Packages to AWS CodeArtifact

New – Add Your Swift Packages to AWS CodeArtifact


Voiced by Polly

Beginning right now, Swift builders who write code for Apple platforms (iOS, iPadOS, macOS, tvOS, watchOS, or visionOS) or for Swift functions working on the server facet can use AWS CodeArtifact to securely retailer and retrieve their bundle dependencies. CodeArtifact integrates with normal developer instruments corresponding to Xcode, xcodebuild, and the Swift Package deal Supervisor (the swift bundle command).

Easy functions routinely embrace dozens of packages. Giant enterprise functions may need tons of of dependencies. These packages assist builders velocity up the event and testing course of by offering code that solves frequent programming challenges corresponding to community entry, cryptographic capabilities, or knowledge format manipulation. Builders additionally embed SDKs–such because the AWS SDKs–to entry distant providers. These packages may be produced by different groups in your group or maintained by third-parties, corresponding to open-source tasks. Managing packages and their dependencies is an integral a part of the software program growth course of. Fashionable programming languages embrace instruments to obtain and resolve dependencies: Maven in Java, NuGet in C#, npm or yarn in JavaScript, and pip in Python simply to say a number of. Builders for Apple platforms use CocoaPods or the Swift Package deal Supervisor (SwiftPM).

Downloading and integrating packages is a routine operation for utility builders. Nonetheless, it presents at the least two vital challenges for organizations.

The primary problem is authorized. Organizations should be certain that licenses for third-party packages are suitable with the anticipated use of licenses in your particular venture and that the bundle doesn’t violate another person’s mental property (IP). The second problem is safety. Organizations should be certain that the included code is protected to make use of and doesn’t embrace again doorways or intentional vulnerabilities designed to introduce safety flaws in your app. Injecting vulnerabilities in fashionable open-source tasks is named a provide chain assault and has turn into more and more fashionable in recent times.

To handle these challenges, organizations usually set up personal bundle servers on premises or within the cloud. Builders can solely use packages vetted by their group’s safety and authorized groups and made accessible by way of personal repositories.

AWS CodeArtifact is a managed service that lets you safely distribute packages to your inside groups of builders. There isn’t any want to put in, handle, or scale the underlying infrastructure. We maintain that for you, supplying you with extra time to work in your apps as an alternative of the software program growth infrastructure.

I’m excited to announce that CodeArtifact now helps native Swift packages, along with npm, PyPI, Maven, NuGet, and generic bundle codecs. Swift packages are a well-liked option to bundle and distribute reusable Swift code components. To learn to create your individual Swift bundle, you’ll be able to comply with this tutorial. The neighborhood has additionally created greater than 6,000 Swift packages that you need to use in your Swift functions.

Now you can publish and obtain your Swift bundle dependencies out of your CodeArtifact repository within the AWS Cloud. CodeArtifact SwiftPM works with present developer instruments corresponding to Xcode, VSCode, and the Swift Package deal Supervisor command line device. After your packages are saved in CodeArtifact, you’ll be able to reference them in your venture’s Package deal.swift file or in your Xcode venture, in the same manner you employ Git endpoints to entry public Swift packages.

After the configuration is full, your network-jailed construct system will obtain the packages from the CodeArtifact repository, guaranteeing that solely permitted and managed packages are used throughout your utility’s construct course of.

How To Get Began
As common on this weblog, I’ll present you the way it works. Think about I’m engaged on an iOS utility that makes use of Amazon DynamoDB as a database. My utility embeds the AWS SDK for Swift as a dependency. To adjust to my group insurance policies, the appliance should use a particular model of the AWS SDK for Swift, compiled in-house and permitted by my group’s authorized and safety groups. On this demo, I present you ways I put together my surroundings, add the bundle to the repository, and use this particular bundle construct as a dependency for my venture.

For this demo, I give attention to the steps particular to Swift packages. You may learn the tutorial written by my colleague Steven to get began with CodeArtifact.

I exploit an AWS account that has a bundle repository (MySwiftRepo) and area (stormacq-test) already configured.

CodeArtifact repository

To let SwiftPM acess my CodeArtifact repository, I begin by gathering an authentication token from CodeArtifact.

export CODEARTIFACT_AUTH_TOKEN=`aws codeartifact get-authorization-token 
                                     --domain stormacq-test              
                                     --domain-owner 012345678912         
                                     --query authorizationToken          
                                     --output textual content`

Word that the authentication token expires after 12 hours. I need to repeat this command after 12 hours to acquire a contemporary token.

Then, I request the repository endpoint. I cross the area title and area proprietor (the AWS account ID). Discover the --format swift choice.

export CODEARTIFACT_REPO=`aws codeartifact get-repository-endpoint  
                               --domain stormacq-test               
                               --domain-owner 012345678912          
                               --format swift                       
                               --repository MySwiftRepo             
                               --query repositoryEndpoint           
                               --output textual content`

Now that I’ve the repository endpoint and an authentication token, I exploit the AWS Command Line Interface (AWS CLI) to configure SwiftPM on my machine.

SwiftPM can retailer the repository configurations at person stage (within the file ~/.swiftpm/configurations) or at venture stage (within the file <your venture>/.swiftpm/configurations). By default, the CodeArtifact login command creates a project-level configuration to mean you can use completely different CodeArtifact repositories for various tasks.

I exploit the AWS CLI to configure SwiftPM on my construct machine.

aws codeartifact login          
    --tool swift                
    --domain stormacq-test      
    --repository MySwiftRepo    
    --namespace aws             
    --domain-owner 012345678912

The command invokes swift package-registry login with the right choices, which in flip, creates the required SwiftPM configuration recordsdata with the given repository title (MySwiftRepo) and scope title (aws).

Now that my construct machine is prepared, I put together my group’s permitted model of the AWS SDK for Swift bundle after which I add it to the repository.

git clone https://github.com/awslabs/aws-sdk-swift.git
pushd aws-sdk-swift
swift bundle archive-source
mv aws-sdk-swift.zip ../aws-sdk-swift-0.24.0.zip

Lastly, I add this bundle model to the repository.

When utilizing Swift 5.9 or more moderen, I can add my bundle to my personal repository utilizing the SwiftPM command:

swift package-registry publish           

The variations of Swift earlier than 5.9 don’t present a swift package-registry publish command. So, I exploit the curl command as an alternative.

curl  -X PUT 
      --user "aws:$CODEARTIFACT_AUTH_TOKEN"               
      -H "Settle for: utility/vnd.swift.registry.v1+json" 
      -F source-archive="@aws-sdk-swift-0.24.0.zip"       

Discover the format of the bundle title after the URI of the repository: <scope>/<bundle title>/<bundle model>. The bundle model should comply with the semantic versioning scheme.

I can use the CLI or the console to confirm that the bundle is obtainable within the repository.

CodeArtifact List Packages

aws codeartifact list-package-versions      
                  --domain stormacq-test    
                  --repository MySwiftRepo  
                  --format swift            
                  --namespace aws           
                  --package aws-sdk-swift
    "variations": [
            "version": "0.24.0",
            "revision": "6XB5O65J8J3jkTDZd8RMLyqz7XbxIg9IXpTudP7THbU=",
            "status": "Published",
            "origin": {
                "domainEntryPoint": {
                    "repositoryName": "MySwiftRepo"
                "originType": "INTERNAL"
    "defaultDisplayVersion": "0.24.0",
    "format": "swift",
    "bundle": "aws-sdk-swift",
    "namespace": "aws"

Now that the bundle is obtainable, I can use it in my tasks as common.

Xcode makes use of SwiftPM instruments and configuration recordsdata I simply created. So as to add a bundle to my Xcode venture, I choose the venture title on the left pane, after which I choose the Package deal Dependencies tab. I can see the packages which might be already a part of my venture. So as to add a personal bundle, I select the + signal beneath Packages.

Xcode add a package as dependency to a project

On the highest proper search area, I enter aws.aws-sdk-swift (that is <scope title>.<bundle title>). After a second or two, the bundle title seems on the checklist. On the highest proper facet, you’ll be able to confirm the supply repository (subsequent to the Registry label). Earlier than deciding on the Add Package deal button, choose the model of the bundle, identical to you do for publicly accessible packages.

Add a private package from Codeartifact on Xcode

Alternatively, for my server-side or command-line functions, I add the dependency within the Package deal.swift file. I additionally use the format (<scope>.<bundle title>) as the primary parameter of .bundle(id:from:)operate.

    dependencies: [
        .package(id: "aws.aws-sdk-swift", from: "0.24.0")

After I sort swift bundle replace, SwiftPM downloads the bundle from the CodeArtifact repository.

Issues to Know
There are some issues to bear in mind earlier than importing your first Swift packages.

  • Make sure to replace to the newest model of the CLI earlier than making an attempt any command proven within the previous directions.
  • It’s important to use Swift model 5.8 or newer to make use of CodeArtifact with the swift bundle command. On macOS, the Swift toolchain comes with Xcode. Swift 5.8 is obtainable on macOS 13 (Ventura) and Xcode 14. On Linux and Home windows, you’ll be able to obtain the Swift toolchain from swift.org.
  • It’s important to use Xcode 15 in your iOS, iPadOS, tvOS, or watchOS functions. I examined this with Xcode 15 beta8.
  • The swift package-registry publish command is obtainable with Swift 5.9 or newer. If you use Swift 5.8, you need to use curlto add your bundle, as I confirmed within the demo (or use any HTTP consumer of your alternative).
  • Swift packages have the idea of scope. A scope offers a namespace for associated packages inside a bundle repository. Scopes are mapped to CodeArtifact namespaces.
  • The authentication token expires after 12 hours. We propose writing a script to automate its renewal or utilizing a scheduled AWS Lambda operate and securely storing the token in AWS Secrets and techniques Supervisor (for instance).

If Xcode cannot discover your personal bundle, double-check the registry configuration in ~/.swiftpm/configurations/registries.json. Specifically, test if the scope title is current. Additionally confirm that the authentication token is current within the keychain. The title of the entry is the URL of your repository. You may confirm the entries within the keychain with the /Utility/Utilities/Keychain Entry.app utility or utilizing the safety command line device.

safety find-internet-password                                                  
          -s "stormacq-test-012345678912.d.codeartifact.us-west-2.amazonaws.com" 

Right here is the SwiftPM configuration on my machine.

cat ~/.swiftpm/configuration/registries.json

  "authentication" : {
    "stormacq-test-012345678912.d.codeartifact.us-west-2.amazonaws.com" : {
      "loginAPIPath" : "/swift/MySwiftRepo/login",
      "sort" : "token"
  "registries" : {
    "aws" : { // <-- that is the scope title!
      "url" : "https://stormacq-test-012345678912.d.codeartifact.us-west-2.amazonaws.com/swift/MySwiftRepo/"
  "model" : 1

Keychain item for codeartifact authentication token

Pricing and Availability
CodeArtifact prices for Swift packages are the identical as for the opposite bundle codecs already supported. CodeArtifact billing is determined by three metrics: the storage (measured in GB per thirty days), the variety of requests, and the information switch out to the web or to different AWS Areas. Information switch to AWS providers in the identical Area will not be charged, which means you’ll be able to run your CICD jobs on Amazon EC2 Mac cases, for instance, with out incurring a cost for the CodeArtifact knowledge switch. As common, the pricing web page has the small print.

CodeArtifact for Swift packages is obtainable in all 13 Areas the place CodeArtifact is obtainable.

Now go construct your Swift functions and add your personal packages to CodeArtifact!

— seb

PS : Are you aware you’ll be able to write Lambda capabilities within the Swift programming language? Examine the short begin information or comply with this 35-minute tutorial.



Please enter your comment!
Please enter your name here