swift-aws-extras

0.2.1

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

What's New

0.2.1

2023-12-29T17:38:54Z

What's Changed

Bug Fixes 🐛

  • Fix Secrets Member Access by @mgacy in #7

Other Changes

Full Changelog: 0.2.0...0.2.1

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: Thu Apr 11 2024 23:56:51 GMT-0900 (Hawaii-Aleutian Daylight Time)