swift-aws-extras

0.3.0

Swifty helpers for working with the AWS SDK.
Mobelux/swift-aws-extras

What's New

0.3.0

2024-05-13T21:12:13Z

What's Changed

Other Changes

  • Update Persistence with attributeModifier Member by @mgacy in #9

Full Changelog: 0.2.1...0.3.0

AWS Extras

Swifty helpers for working with the Swift AWS SDK.

📱 Requirements

Swift 5.7 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/Mobelux/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(
    ["recipient@mail.com"],
    "sender@mail.com",
    "Subject",
    .text("Plain text email content")
)

To send an email with both plain text and HTML:

let messageID = try await sender.send(
    ["recipient@mail.com"],
    "sender@mail.com",
    "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"
])

Description

  • Swift Tools 5.7.0
View More Packages from this Author

Dependencies

Last updated: Wed Oct 23 2024 02:54:05 GMT-0900 (Hawaii-Aleutian Daylight Time)