Swiftpack.co - soto-archive/aws-sdk-appleos as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by soto-archive.
soto-archive/aws-sdk-appleos 0.5.0
AWS SDK for Swift supporting Apple platforms, including iOS, as first-class citizens.
⭐️ 9
🕓 4 years ago
iOS macOS tvOS
.package(url: "https://github.com/soto-archive/aws-sdk-appleos.git", from: "0.5.0")

Now that AWSSDK Swift supports iOS and macOS as first class citizens, AWSSDK AppleOS has been deprecated. It will not receive any new updates. Please move to using AWSSDKSwift to keep up to date with changes.

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 [email protected] 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
Last commit: 4 years ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

v0.5.0
4 years ago

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.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics