Swiftpack.co - Package - swift-aws/aws-sdk-appleos

AWSSDK AppleOS

Version of the AWS SDK for the Swift programming language that supports Apple platforms (including iOS) as first class citizens. This repository is based off the aws-sdk-swift repository. As this version is reliant on Network.framework it only works for Apple platforms, but it does support iOS unlike aws-sdk-swift.

Swift 5.0

Supported Platforms and Swift Versions

| Platform | Version | |---|:---:| |iOS | v12.2 | |macOS | v10.14 | |tvOS | v12.2 |

Documentation

Visit the aws-sdk-swift documentation for instructions and browsing api references.

Swift NIO

This client utilizes Swift NIO to power its interactions with AWS. It returns an EventLoopFuture in order to allow non-blocking frameworks to use this code. This version of aws-adk-swift uses the NIOTransportServices to provide network connectivity. The NIOTransportServices package is reliant on Network.framework. This means it can support all Apple platforms but is not available for Linux. Please see the Swift NIO documentation for more details, and please let us know via an Issue if you have questions!

Installation

Swift Package Manager

AWS SDK Apple OS uses the Swift Package manager. It is recommended you create a swift package that only includes the AWS services you are interested in. The easiest method to do this is create an empty folder, enter this folder and type swift package init. This will create a Package.swift file. Add the package dependency on package https://github.com/swift-aws/aws-sdk-appleos.git. Add the services you are using in the dependency list for your target. See below for an example. Make sure you add the line indicating the platforms you are targetting. In future versions of XCode it will be possible to include Swift Package files directly into your project. In the meantime the method to add aws-sdk-appleos into your project is as follows.

  • Create an xcodeproj file. Run swift package generate-xcodeproj in the same folder as your Package.swift file.
  • Open your project and add the generated xcodeproj in to your project.
  • Include the framework for the services you require in the Embedded Binaries for the project.

Example Package.swift

import PackageDescription

let package = Package(
    name: "MyAWSLib",
    platforms: [.iOS("12.2"), .macOS(.v10_14)],
    dependencies: [
        .package(url: "https://github.com/swift-aws/aws-sdk-appleos.git", from: "0.5.0")
    ],
    targets: [
      .target(
          name: "MyAWSLib",
          dependencies: ["S3", "SES", "CloudFront", "ELBV2", "IAM", "Kinesis"]),
      .testTarget(
          name: "MyAWSToolTests",
          dependencies: ["MyAWSLib"]),
    ]
)

Carthage

Not supported yet

Cocoapods

Not supported yet

Contributing

All developers should feel welcome and encouraged to contribute to aws-sdk-swift.

As contributors and maintainers of this project, and in the interest of fostering an open and welcoming community, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.

To contribute a feature or idea to aws-sdk-swift, submit an issue and fill in the template. If the request is approved, you or one of the members of the community can start working on it. It is prefereable that pull requests are made in the original swift repositories and not the appleos versions of the code. If you have a change that is specific to apple OS then make a pull request to the appleos branch in repositories aws-sdk-swift or aws-sdk-swift-core.

If you find a bug, please submit an issue with a failing test case displaying the bug or create an issue.

If you find a security vulnerability, please contact yuki@miketokyo.com and reach out on the #aws channel on the Vapor Discord as soon as possible. We take these matters seriously.

Configuring Credentials

Before using the SDK, ensure that you've configured credentials.

Pass the Credentials to the AWS Service struct directly

All of the AWS Services's initializers accept accessKeyId and secretAccessKey

let ec2 = EC2(
    accessKeyId: "YOUR_AWS_ACCESS_KEY_ID",
    secretAccessKey: "YOUR_AWS_SECRET_ACCESS_KEY"
)

Using aws-sdk-swift

AWS Swift Modules can be imported into any swift project. Each module provides a struct that can be initialized, with instance methods to call aws services. See documentation for details on specific services.

The underlying aws-sdk-swift httpclient returns a swift-nio EventLoopFuture object. An EventLoopFuture is not the response, but rather a container object that will be populated with the response sometime later. In this manner calls to AWS do not block the main thread.

However, operations that require inspection or use of the response require code to be written in a slightly different manner that equivalent synchronous logic. There are numerous references available online to aid in understanding this concept.

The recommended manner to interact with futures is chaining.

import AWSSDKSwiftCore
import S3 //ensure this module is specified as a dependency in your package.swift

let bucket = "my-bucket"

let s3 = S3(
    accessKeyId: "Your-Access-Key",
    secretAccessKey: "Your-Secret-Key",
    region: .uswest2
)

func createPutGetObject() throws {
    // Create Bucket, Put an Object, Get the Object
    let createBucketRequest = S3.CreateBucketRequest(bucket: bucket)

    let response = s3.createBucket(createBucketRequest).then { response -> Future<S3.PutObjectOutput> in
        // Upload text file to the s3
        let bodyData = "hello world".data(using: .utf8)!
        let putObjectRequest = S3.PutObjectRequest(acl: .publicRead, body: bodyData, bucket: bucket, contentLength: Int64(bodyData.count), key: "hello.txt")
        return s3.putObject(putObjectRequest)
    }.flatMap { response -> Future<S3.GetObjectOutput> in
        let getObjectRequest = S3.GetObjectRequest(bucket: bucket, key: "hello.txt")
        return s3.getObject(getObjectRequest)
    }
    
    response.whenSuccess { response in
        if let body = response.body {
            print(String(data: body, encoding: .utf8)!)
        }
    }
    try _ = response.wait()
}

License

aws-sdk-swift is released under the Apache License, Version 2.0. See LICENSE for details.

Github

link
Stars: 9
Help us keep the lights on

Used By

Total: 0

Releases

0.5.0 - Sep 17, 2019

Using v0.4.0 of aws-sdk-appleos-core

  • Sync service model files to v1.23.12 of aws-sdk-go.
  • We are now using Stencil to generate our swift service files from the AWS model files.
  • Deprecated api commands are now marked deprecated in swift.
  • Output xml namespace as member of AWSShape where available
  • Added validation code for AWSShape members wherever it is supplied in the model files. Will validate min, max values for numbers, string and collection length and validate strings against regex patterns.
  • Autogenerate idempotency tokens.
  • Remove all AWSShape's not tagged as an input or output of an api function.
  • Stop partition endpoint overwriting the region endpoint where a default value is being used for the region endpoint.
  • let client: AWSClient in service classes is now public.
  • Using Int instead of Int32 in service files.
  • Include sessionToken in service init() functions to allow for access to services via tokens returned from STS.
  • Include middlewares in service init() functions to allow user access to requests and responses as they are processed.
  • Errors thrown by service files all conform to CustomStringConvertible.
  • API functions are not tagged as throwing anymore.

Service changes

  • S3 Add additional regions to BucketLocationConstraint enum.
  • S3 Fixup response from GetBucketLocation so it is parsed correctly.
  • S3 Don't attempt to setup virtual bucket addresses for non amazon endpoints.
  • S3 Support metadata headers for Get/Put/HeadObject
  • Route53 Make Marker optional in ListHealthChecksResponse, ListHostedZonesResponse and ListReusableDelegationSetsResponse.
  • CloudFront Capitalized HttpVersion enum entries.

0.4.1 - Aug 19, 2019

0.4.0 - Aug 18, 2019

  • Using release v0.3.x of aws-sdk-appleos-core
  • AWS Service files are now generated using Stencil
  • Deprecated API calls are flagged in code
  • XMLNamespace is added to AWSShape where required
  • Added validate() function to each shape to ensure min, max and pattern fields from model files are respected
  • Remove AWSShapes that aren't used in either the input or output of an api call
  • Autogenerate idempotency tokens
  • Add additional regions to S3.BucketLocationConstraint enum
  • Stop partition endpoint overwriting the endpoint when it should be using the default value.
  • Fixed S3.GetBucketLocation()

0.3.2 - Jul 19, 2019

  • Using release v0.2.4 of aws-sdk-appleos-core
  • Sync service models files to v1.20.17 of aws-sdk-go. See versions 1.20.17 to 1.20.12 for details of changes.
  • Deal with model files that set location to "headers" instead of "header". Fixes some S3 issues.

0.3.1 - Jul 8, 2019

  • Using release 0.2.2 of aws-sdk-appleos-core
  • Fixed Backup and DirectoryService name clashes with system frameworks. Appended "AWS" at front of name.
  • Fixed PlatformValues enum in EC2.