Skip to content

Latest commit

 

History

History
39 lines (29 loc) · 1.26 KB

readme.md

File metadata and controls

39 lines (29 loc) · 1.26 KB

IndiePitcherLambdaSwiftExample

Example demonstrating how to send an email using IndiePitcher from an AWS Lambda function written using the Swift programming language.

// Import the module
import AWSLambdaRuntime
import AsyncHTTPClient
import IndiePitcherSwift

@main
struct MyLambda: SimpleLambdaHandler {

    private let indiePitcherApiKey = "sc_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

    func handle(_ event: String, context: LambdaContext) async throws -> String {

        let indiePitcher = IndiePitcher(apiKey: indiePitcherApiKey)

        let emailBody = """
            This is an email sent from a **AWS Lambda function**!
            """

        try await indiePitcher.sendEmail(
            data: .init(
                to: "[email protected]", subject: "Hello from AWS Lambda!", body: emailBody,
                bodyFormat: .markdown))

        return "Email sent!"
    }
}
  • Create a free account at https://indiepitcher.com
  • Create a new project
  • Create an API key for your project
  • Open main.swift and replace sc_xxxxxxxx with your access token
  • Change the email to your email.
  • Launch the function locally curl -v --header "Content-Type:\ application/json" --data @test-data/request.json http://127.0.0.1:7000/invoke