Skip to content

mgacy/swift-aws-extras

Repository files navigation

AWS Extras

Swifty helpers for working with the Swift AWS SDK.

Requirements

Swift 5.9 toolchain with Swift Package Manager.

Installation

AWS Extras is distributed using the Swift Package Manager. To install it into a project, add it as a dependency within your Package.swift manifest:

dependencies: [
    .package(url: "https://github.com/mgacy/swift-aws-extras.git", from: "0.1.0")
]

Then, add the relevant product to any targets that need access to the library:

.product(name: "<product>", package: "swift-aws-extras"),

Where <product> is one of the following:

  • EmailSender
  • Persistence
  • Secrets

Usage

EmailSender

Initialize an EmailSender:

let sender = try await EmailSenderFactory.live().make()

To send an email with a plain text body:

let messageID = try await sender.send(
    ["[email protected]"],
    "[email protected]",
    "Subject",
    .text("Plain text email content")
)

To send an email with both plain text and HTML:

let messageID = try await sender.send(
    ["[email protected]"],
    "[email protected]",
    "Subject",
    .combined("Plain text email content", "<!doctype html>\n<html>...</html>")
)

Persistence

Add AttributeValueConvertible conformance to model types:

struct MyModel: Codable {
    let name: String
    let value: Int
}

extension MyModel: AttributeValueConvertible {
    var attributes: [String: AttributeValue] {
        [
            CodingKeys.name: .s(name),
            CodingKeys.value: .n(String(value))
        ].attributeValues()
    }
}

Initialize Persistence:

let persistence = try await PersistenceFactory.make(
    "us-east-1",
    "TableName)

Persist a model instance:

let model = MyModel(name: "foo", value: 42)
try await persistence.put(model)

Secrets

Initialize Secrets with a region:

let secrets = Secrets.live(region: "us-east-1")

Retrieve a secret string by its id:

let secret = try await secrets.string("my-secret-id")

Retrieve secret data by its id:

let secret = try await secrets.data("my-secret-id")

Retrieve multiple secrets:

let secrets = try await secrets.batch([
    "my-secret-id",
    "my-other-secret-id"
])

About

Swifty helpers for working with the AWS SDK.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages