SlideShare a Scribd company logo
1 of 33
Download to read offline
SERVERLESS IN SWIFT LIKE A BREEZE
ANDREA SCUDERI
SENIOR IOS ENGINEER @ JUST EAT TAKEAWAY
NSLondon
2023.2
AGENDA
▸ Demo App with Serverless
▸ App & Serverless Architecture
▸ Code Structure
▸ Code Generation
▸ Deployment
▸ Why Serverless, Why Swift? Why Breeze?
FULL STACK SWIFT
DEMO APP
GITHUB.COM/SWIFT-SPRINTER/BREEZEDEMOAPP
▸ SwiftUI
▸ Apple Sign In
▸ Serverless API in Swift
▸ CRUD (Create, Read, Update, Delete)
DEMO APP
DATA MODEL
public struct Form: Codable {
public var key: String
public let name: String
public let fields: [Field]
public var createdAt: String?
public var updatedAt: String?
public init(key: String,
name: String,
fields: [Field],
createdAt: String? = nil,
updatedAt: String? = nil) {
self.key = key
self.name = name
self.fields = fields
self.createdAt = createdAt
self.updatedAt = updatedAt
}
enum CodingKeys: String, CodingKey {
case key = "formKey"
case name
case fields
case createdAt
case updatedAt
}
}
public struct Field: Codable {
public let question: String
public let answer: String?
public let choices: [String]?
public let selected: [String]?
public let type: FieldType
public init(question: String,
answer: String? = nil,
choices: [String]? = nil,
selected: [String]? = nil,
type: FieldType) {
self.question = question
self.answer = answer
self.choices = choices
self.selected = selected
self.type = type
}
}
public enum FieldType: String, Codable {
case text
case option
case multiOption
}
SERVERLESS NO-SQL DB
AWS DYNAMODB
{
"formKey": {
"S": "114800A1-162F-4877-81BC-96E9A42E6559"
},
"createdAt": {
"S": "2023-05-06T08:31:37.866Z"
},
"fields": {
"L": [
{
"M": {
"choices": {
"L": [
{
"S": "Cost savings 💰 "
},
{
"S": "Performance ⚡ "
},
{
"S": "Scalability 🚀 "
},
{
"S": "Infrastructure as a Code 💨 "
}
]
},
"question": {
"S": "What is the main benefit of Serverless computing?"
},
"selected": {
"L": [
{
"S": "Cost savings 💰 "
},
{
"S": "Performance ⚡ "
},
{
"S": "Infrastructure as a Code 💨 "
},
{
"S": "Scalability 🚀 "
}
]
},
"type": {
"S": "multiOption"
}
}
},
{
"M": {
MOBILE & SERVERLESS
ARCHITECTURE
Mobile App API Gateway
HTTP/REST
+ (Bearer Token)
OAUTH 2.0
PROVIDER
JWT Token
https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-jwt-authorizer.html
Validation
SERVERLESS ARCHITECTURE
MOBILE & SERVERLESS
CODE ARCHITECTURE
BreezeLambdaAPIClient SharedModel
public struct Form: Codable {
public var key: String
public let name: String
public let fields: [Field]
public var createdAt: String?
public var updatedAt: String?
public init(key: String,
name: String,
fields: [Field],
createdAt: String? = nil,
updatedAt: String? = nil) {
self.key = key
self.name = name
self.fields = fields
self.createdAt = createdAt
self.updatedAt = updatedAt
}
enum CodingKeys: String, CodingKey {
case key = "formKey"
case name
case fields
case createdAt
case updatedAt
}
}
iOS - Swift
…
BreezeLambdaAPI BreezeDynamoDBService
SOTO
SHOW ME THE CODE!
APP API SERVICE
SERVICE-BASED BREEZE LAMBDA API CLIENT
struct FormService: FormServing {
private let apiClient: BreezeLambdaAPIClient<FeedbackForm>
private let session: SessionService
private var token: String? {
session.userSession?.jwtToken
}
init(session: SessionService) {
guard var env = try? APIEnvironment.dev() else {
fatalError("Invalid Environment")
}
env.logger = Logger()
self.session = session
self.apiClient = BreezeLambdaAPIClient<FeedbackForm>(env: env, path: "forms", additionalHeaders: [:])
}
func create(form: FeedbackForm) async throws -> FeedbackForm {
try await apiClient.create(token: token, item: form)
}
func read(key: String) async throws -> FeedbackForm {
try await apiClient.read(token: token, key: key)
}
func update(form: FeedbackForm) async throws -> FeedbackForm {
try await apiClient.update(token: token, item: form)
}
Data Model
Environment API PATH
JWT Token
APP API SERVICE
BREEZE LAMBDA API CLIENT
struct Environment {
static func dev() throws -> APIClientEnv {
try APIClientEnv(session: URLSession.shared, baseURL: "<API GATEWAY BASE URL FROM SERVERLESS DEPLOY>")
}
}
extension FeedbackForm: KeyedCodable {}
struct Logger: APIClientLogging {
func log(request: URLRequest) {
print(request)
}
func log(data: Data, for response: URLResponse) {
print(response)
let value = String(data: data, encoding: .utf8) ?? ""
print(value)
}
}
LAMBDA CODE
ONE LINE OF CODE !!!
import Foundation
import BreezeLambdaAPI
import BreezeDynamoDBService
import SharedModel
extension Form: BreezeCodable { }
BreezeLambdaAPI<Form>.main()
public protocol BreezeCodable: Codable {
var key: String { get set }
var createdAt: String? { get set }
var updatedAt: String? { get set }
}
SWIFT !!!
YES, I CAN UNDERSTAND IT!
INFRASTRUCTURE AS A CODE
SERVERLESS.YML
▸ API Gateway v2
▸ Lambda
▸ DynamoDB
▸ IAM
▸ Package
SERVERLESS.YML ?!?
LOOKS QUITE HARD !
HOW DO I START?
▸ A SMALLER YML CONFIG
▸ COMMAND LINE TOOL GENERATES:
▸ PROJECT FOLDER
▸ SWIFT PACKAGE
▸ SERVERLESS.YML
▸ BUILD SCRIPT
▸ DEPLOYMENT SCRIPT
SERVERLESS WITH BREEZE
CODE GENERATION WITH BREEZE
service: swift-breeze-rest-form-api
awsRegion: us-east-1
swiftVersion: 5.7.3
swiftConfiguration: release
packageName: BreezeFormAPI
buildPath: build
cors: false
authorizer: #optional
name: appleJWT
type: JWTAuthorizer
issuerUrl: https://appleid.apple.com
audience:
- com.andrea.DemoApp #APP BUNDLE ID
breezeLambdaAPI:
targetName: FormAPI
itemCodable: Form
itemKey: formKey
httpAPIPath: /forms
dynamoDBTableNamePrefix: forms
CODE GENERATION
BREEZE COMMAND LINE
swift run breeze -c breeze.yml -t .build/temp
CODE GENERATION
BREEZE COMMAND LINE
CODE BUILD
BREEZE BUILD
./build.sh
❌
build
Docker image: swift:5.7-amazonlinux2
CODE BUILD
BREEZE BUILD
./build.sh
SERVERLESS DEPLOY
BREEZE DEPLOY
./deploy.sh
serverless.yml
build Deployment con
fi
guration
CloudFormation AWS Deployment
serverless deploy
SERVERLESS DEPLOY
BREEZE DEPLOY
./deploy.sh
SERVERLESS LIKE A BREEZE!
BREEZE WORKFLOW
STEP BY STEP WORKFLOW
▸ Git Clone https://github.com/swift-sprinter/Breeze
▸ Copy Breeze.yml con
fi
g from the README
▸ Add the Authorizer to the con
fi
g if you want to secure the API!!!
▸ Adjust the con
fi
guration
▸ Generate the code and customise the data model
▸ Build the Lambdas
▸ Deploy the Serverless
▸ Implement your app using the BreezeLambdaAPIClient
WHY SERVERLESS?
WHY SWIFT?
WHY BREEZE?
WHY SERVERLESS? WHY SWIFT? WHY BREEZE?
▸ Scalability
▸ Reduced Operational Overhead
▸ Pay per use
▸ Faster Time to market
▸ Easy Integration
WHY SERVERLESS?
WHY SERVERLESS? WHY SWIFT? WHY BREEZE?
▸ iOS Developers ❤ it!
▸ No need to learn a new language
▸ Modern and performant language
▸ Safe
▸ Expressive
▸ Fast
WHY SWIFT?
▸ Quick Start!
▸ Project setup
▸ Build
▸ Deploy
▸ Full control
▸ Adaptable
▸ Open Source
WHY SERVERLESS? WHY SWIFT? WHY BREEZE?
WHY BREEZE?
GITHUB BREEZE
GITHUB.COM/SWIFT-SPRINTER/BREEZE
THANK YOU!
ANDREA SCUDERI - SENIOR IOS ENGINEER @ JUST EAT TAKEAWAY
STAY IN TOUCH!
▸ Twitter: @andreascuderi13
▸ Linkedin: https://www.linkedin.com/in/andreascuderi/
▸ Medium: https://medium.com/@andreascuderi73

More Related Content

Similar to Serverless in Swift like a Breeze

Application Server-less Web Applications - Serverless Toronto Meetup
Application Server-less Web Applications - Serverless Toronto Meetup Application Server-less Web Applications - Serverless Toronto Meetup
Application Server-less Web Applications - Serverless Toronto Meetup Daniel Zivkovic
 
Engineering Efficiency in LINE
Engineering Efficiency in LINEEngineering Efficiency in LINE
Engineering Efficiency in LINEHuy Do
 
DevFest 2022 - GitHub Actions를 활용한 Flutter 배포 자동화하기
DevFest 2022 - GitHub Actions를 활용한 Flutter 배포 자동화하기DevFest 2022 - GitHub Actions를 활용한 Flutter 배포 자동화하기
DevFest 2022 - GitHub Actions를 활용한 Flutter 배포 자동화하기SuJang Yang
 
Firebird 3: provider-based architecture, plugins and OO approach to API
Firebird 3: provider-based architecture, plugins and OO approach to API Firebird 3: provider-based architecture, plugins and OO approach to API
Firebird 3: provider-based architecture, plugins and OO approach to API Mind The Firebird
 
Build a notepad application with PHP, MongoDB, and IBM Bluemix - by Vikram Va...
Build a notepad application with PHP, MongoDB, and IBM Bluemix - by Vikram Va...Build a notepad application with PHP, MongoDB, and IBM Bluemix - by Vikram Va...
Build a notepad application with PHP, MongoDB, and IBM Bluemix - by Vikram Va...Carlos Tomas
 
Electron - cross platform desktop applications made easy
Electron - cross platform desktop applications made easyElectron - cross platform desktop applications made easy
Electron - cross platform desktop applications made easyUlrich Krause
 
2020.02.15 DelEx - CI/CD in AWS Cloud
2020.02.15 DelEx - CI/CD in AWS Cloud2020.02.15 DelEx - CI/CD in AWS Cloud
2020.02.15 DelEx - CI/CD in AWS CloudPeter Salnikov
 
Serverless Spring by Stephane Maldini
Serverless Spring by Stephane MaldiniServerless Spring by Stephane Maldini
Serverless Spring by Stephane MaldiniVMware Tanzu
 
[JMaghreb 2014] Developing JavaScript Mobile Apps Using Apache Cordova
[JMaghreb 2014] Developing JavaScript Mobile Apps Using Apache Cordova[JMaghreb 2014] Developing JavaScript Mobile Apps Using Apache Cordova
[JMaghreb 2014] Developing JavaScript Mobile Apps Using Apache CordovaHazem Saleh
 
Reactive application using meteor
Reactive application using meteorReactive application using meteor
Reactive application using meteorSapna Upreti
 
Symfony2 for Midgard Developers
Symfony2 for Midgard DevelopersSymfony2 for Midgard Developers
Symfony2 for Midgard DevelopersHenri Bergius
 
Ane for 9ria_cn
Ane for 9ria_cnAne for 9ria_cn
Ane for 9ria_cnsonicxs
 
Serverless Application Development with SAM
Serverless Application Development with SAMServerless Application Development with SAM
Serverless Application Development with SAMAmazon Web Services
 
Application Lifecycle Management in a Serverless World
Application Lifecycle Management in a Serverless WorldApplication Lifecycle Management in a Serverless World
Application Lifecycle Management in a Serverless WorldAmazon Web Services
 
Serverless - Developers.IO 2019
Serverless - Developers.IO 2019Serverless - Developers.IO 2019
Serverless - Developers.IO 2019Shuji Watanabe
 
ANZ Dev Lounge Session - Feb 2017
ANZ Dev Lounge Session - Feb 2017ANZ Dev Lounge Session - Feb 2017
ANZ Dev Lounge Session - Feb 2017Amazon Web Services
 
How dorma+kaba leverages and deploys on CloudFoundry - CloudFoundry Summit Eu...
How dorma+kaba leverages and deploys on CloudFoundry - CloudFoundry Summit Eu...How dorma+kaba leverages and deploys on CloudFoundry - CloudFoundry Summit Eu...
How dorma+kaba leverages and deploys on CloudFoundry - CloudFoundry Summit Eu...Adriano Raiano
 

Similar to Serverless in Swift like a Breeze (20)

Hexagonal architecture
Hexagonal architectureHexagonal architecture
Hexagonal architecture
 
Application Server-less Web Applications - Serverless Toronto Meetup
Application Server-less Web Applications - Serverless Toronto Meetup Application Server-less Web Applications - Serverless Toronto Meetup
Application Server-less Web Applications - Serverless Toronto Meetup
 
Engineering Efficiency in LINE
Engineering Efficiency in LINEEngineering Efficiency in LINE
Engineering Efficiency in LINE
 
DevFest 2022 - GitHub Actions를 활용한 Flutter 배포 자동화하기
DevFest 2022 - GitHub Actions를 활용한 Flutter 배포 자동화하기DevFest 2022 - GitHub Actions를 활용한 Flutter 배포 자동화하기
DevFest 2022 - GitHub Actions를 활용한 Flutter 배포 자동화하기
 
Firebird 3: provider-based architecture, plugins and OO approach to API
Firebird 3: provider-based architecture, plugins and OO approach to API Firebird 3: provider-based architecture, plugins and OO approach to API
Firebird 3: provider-based architecture, plugins and OO approach to API
 
Build a notepad application with PHP, MongoDB, and IBM Bluemix - by Vikram Va...
Build a notepad application with PHP, MongoDB, and IBM Bluemix - by Vikram Va...Build a notepad application with PHP, MongoDB, and IBM Bluemix - by Vikram Va...
Build a notepad application with PHP, MongoDB, and IBM Bluemix - by Vikram Va...
 
Electron - cross platform desktop applications made easy
Electron - cross platform desktop applications made easyElectron - cross platform desktop applications made easy
Electron - cross platform desktop applications made easy
 
2020.02.15 DelEx - CI/CD in AWS Cloud
2020.02.15 DelEx - CI/CD in AWS Cloud2020.02.15 DelEx - CI/CD in AWS Cloud
2020.02.15 DelEx - CI/CD in AWS Cloud
 
Serverless Spring by Stephane Maldini
Serverless Spring by Stephane MaldiniServerless Spring by Stephane Maldini
Serverless Spring by Stephane Maldini
 
[JMaghreb 2014] Developing JavaScript Mobile Apps Using Apache Cordova
[JMaghreb 2014] Developing JavaScript Mobile Apps Using Apache Cordova[JMaghreb 2014] Developing JavaScript Mobile Apps Using Apache Cordova
[JMaghreb 2014] Developing JavaScript Mobile Apps Using Apache Cordova
 
Reactive application using meteor
Reactive application using meteorReactive application using meteor
Reactive application using meteor
 
Symfony2 for Midgard Developers
Symfony2 for Midgard DevelopersSymfony2 for Midgard Developers
Symfony2 for Midgard Developers
 
Deep Dive on Serverless Stack
Deep Dive on Serverless StackDeep Dive on Serverless Stack
Deep Dive on Serverless Stack
 
Ane for 9ria_cn
Ane for 9ria_cnAne for 9ria_cn
Ane for 9ria_cn
 
Serverless Application Development with SAM
Serverless Application Development with SAMServerless Application Development with SAM
Serverless Application Development with SAM
 
Application Lifecycle Management in a Serverless World
Application Lifecycle Management in a Serverless WorldApplication Lifecycle Management in a Serverless World
Application Lifecycle Management in a Serverless World
 
Serverless - Developers.IO 2019
Serverless - Developers.IO 2019Serverless - Developers.IO 2019
Serverless - Developers.IO 2019
 
ANZ Dev Lounge Session - Feb 2017
ANZ Dev Lounge Session - Feb 2017ANZ Dev Lounge Session - Feb 2017
ANZ Dev Lounge Session - Feb 2017
 
Automation day red hat ansible
   Automation day red hat ansible    Automation day red hat ansible
Automation day red hat ansible
 
How dorma+kaba leverages and deploys on CloudFoundry - CloudFoundry Summit Eu...
How dorma+kaba leverages and deploys on CloudFoundry - CloudFoundry Summit Eu...How dorma+kaba leverages and deploys on CloudFoundry - CloudFoundry Summit Eu...
How dorma+kaba leverages and deploys on CloudFoundry - CloudFoundry Summit Eu...
 

Recently uploaded

Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfStefano Stabellini
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 

Recently uploaded (20)

Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdf
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 

Serverless in Swift like a Breeze

  • 1. SERVERLESS IN SWIFT LIKE A BREEZE ANDREA SCUDERI SENIOR IOS ENGINEER @ JUST EAT TAKEAWAY NSLondon 2023.2
  • 2. AGENDA ▸ Demo App with Serverless ▸ App & Serverless Architecture ▸ Code Structure ▸ Code Generation ▸ Deployment ▸ Why Serverless, Why Swift? Why Breeze?
  • 4. DEMO APP GITHUB.COM/SWIFT-SPRINTER/BREEZEDEMOAPP ▸ SwiftUI ▸ Apple Sign In ▸ Serverless API in Swift ▸ CRUD (Create, Read, Update, Delete)
  • 5. DEMO APP DATA MODEL public struct Form: Codable { public var key: String public let name: String public let fields: [Field] public var createdAt: String? public var updatedAt: String? public init(key: String, name: String, fields: [Field], createdAt: String? = nil, updatedAt: String? = nil) { self.key = key self.name = name self.fields = fields self.createdAt = createdAt self.updatedAt = updatedAt } enum CodingKeys: String, CodingKey { case key = "formKey" case name case fields case createdAt case updatedAt } } public struct Field: Codable { public let question: String public let answer: String? public let choices: [String]? public let selected: [String]? public let type: FieldType public init(question: String, answer: String? = nil, choices: [String]? = nil, selected: [String]? = nil, type: FieldType) { self.question = question self.answer = answer self.choices = choices self.selected = selected self.type = type } } public enum FieldType: String, Codable { case text case option case multiOption }
  • 6. SERVERLESS NO-SQL DB AWS DYNAMODB { "formKey": { "S": "114800A1-162F-4877-81BC-96E9A42E6559" }, "createdAt": { "S": "2023-05-06T08:31:37.866Z" }, "fields": { "L": [ { "M": { "choices": { "L": [ { "S": "Cost savings 💰 " }, { "S": "Performance ⚡ " }, { "S": "Scalability 🚀 " }, { "S": "Infrastructure as a Code 💨 " } ] }, "question": { "S": "What is the main benefit of Serverless computing?" }, "selected": { "L": [ { "S": "Cost savings 💰 " }, { "S": "Performance ⚡ " }, { "S": "Infrastructure as a Code 💨 " }, { "S": "Scalability 🚀 " } ] }, "type": { "S": "multiOption" } } }, { "M": {
  • 7. MOBILE & SERVERLESS ARCHITECTURE Mobile App API Gateway HTTP/REST + (Bearer Token) OAUTH 2.0 PROVIDER JWT Token https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-jwt-authorizer.html Validation
  • 9. MOBILE & SERVERLESS CODE ARCHITECTURE BreezeLambdaAPIClient SharedModel public struct Form: Codable { public var key: String public let name: String public let fields: [Field] public var createdAt: String? public var updatedAt: String? public init(key: String, name: String, fields: [Field], createdAt: String? = nil, updatedAt: String? = nil) { self.key = key self.name = name self.fields = fields self.createdAt = createdAt self.updatedAt = updatedAt } enum CodingKeys: String, CodingKey { case key = "formKey" case name case fields case createdAt case updatedAt } } iOS - Swift … BreezeLambdaAPI BreezeDynamoDBService SOTO
  • 10. SHOW ME THE CODE!
  • 11. APP API SERVICE SERVICE-BASED BREEZE LAMBDA API CLIENT struct FormService: FormServing { private let apiClient: BreezeLambdaAPIClient<FeedbackForm> private let session: SessionService private var token: String? { session.userSession?.jwtToken } init(session: SessionService) { guard var env = try? APIEnvironment.dev() else { fatalError("Invalid Environment") } env.logger = Logger() self.session = session self.apiClient = BreezeLambdaAPIClient<FeedbackForm>(env: env, path: "forms", additionalHeaders: [:]) } func create(form: FeedbackForm) async throws -> FeedbackForm { try await apiClient.create(token: token, item: form) } func read(key: String) async throws -> FeedbackForm { try await apiClient.read(token: token, key: key) } func update(form: FeedbackForm) async throws -> FeedbackForm { try await apiClient.update(token: token, item: form) } Data Model Environment API PATH JWT Token
  • 12. APP API SERVICE BREEZE LAMBDA API CLIENT struct Environment { static func dev() throws -> APIClientEnv { try APIClientEnv(session: URLSession.shared, baseURL: "<API GATEWAY BASE URL FROM SERVERLESS DEPLOY>") } } extension FeedbackForm: KeyedCodable {} struct Logger: APIClientLogging { func log(request: URLRequest) { print(request) } func log(data: Data, for response: URLResponse) { print(response) let value = String(data: data, encoding: .utf8) ?? "" print(value) } }
  • 13. LAMBDA CODE ONE LINE OF CODE !!! import Foundation import BreezeLambdaAPI import BreezeDynamoDBService import SharedModel extension Form: BreezeCodable { } BreezeLambdaAPI<Form>.main() public protocol BreezeCodable: Codable { var key: String { get set } var createdAt: String? { get set } var updatedAt: String? { get set } }
  • 14. SWIFT !!! YES, I CAN UNDERSTAND IT!
  • 15. INFRASTRUCTURE AS A CODE SERVERLESS.YML ▸ API Gateway v2 ▸ Lambda ▸ DynamoDB ▸ IAM ▸ Package
  • 17. HOW DO I START?
  • 18. ▸ A SMALLER YML CONFIG ▸ COMMAND LINE TOOL GENERATES: ▸ PROJECT FOLDER ▸ SWIFT PACKAGE ▸ SERVERLESS.YML ▸ BUILD SCRIPT ▸ DEPLOYMENT SCRIPT SERVERLESS WITH BREEZE CODE GENERATION WITH BREEZE service: swift-breeze-rest-form-api awsRegion: us-east-1 swiftVersion: 5.7.3 swiftConfiguration: release packageName: BreezeFormAPI buildPath: build cors: false authorizer: #optional name: appleJWT type: JWTAuthorizer issuerUrl: https://appleid.apple.com audience: - com.andrea.DemoApp #APP BUNDLE ID breezeLambdaAPI: targetName: FormAPI itemCodable: Form itemKey: formKey httpAPIPath: /forms dynamoDBTableNamePrefix: forms
  • 19. CODE GENERATION BREEZE COMMAND LINE swift run breeze -c breeze.yml -t .build/temp
  • 23. SERVERLESS DEPLOY BREEZE DEPLOY ./deploy.sh serverless.yml build Deployment con fi guration CloudFormation AWS Deployment serverless deploy
  • 25. SERVERLESS LIKE A BREEZE!
  • 26. BREEZE WORKFLOW STEP BY STEP WORKFLOW ▸ Git Clone https://github.com/swift-sprinter/Breeze ▸ Copy Breeze.yml con fi g from the README ▸ Add the Authorizer to the con fi g if you want to secure the API!!! ▸ Adjust the con fi guration ▸ Generate the code and customise the data model ▸ Build the Lambdas ▸ Deploy the Serverless ▸ Implement your app using the BreezeLambdaAPIClient
  • 28. WHY SERVERLESS? WHY SWIFT? WHY BREEZE? ▸ Scalability ▸ Reduced Operational Overhead ▸ Pay per use ▸ Faster Time to market ▸ Easy Integration WHY SERVERLESS?
  • 29. WHY SERVERLESS? WHY SWIFT? WHY BREEZE? ▸ iOS Developers ❤ it! ▸ No need to learn a new language ▸ Modern and performant language ▸ Safe ▸ Expressive ▸ Fast WHY SWIFT?
  • 30. ▸ Quick Start! ▸ Project setup ▸ Build ▸ Deploy ▸ Full control ▸ Adaptable ▸ Open Source WHY SERVERLESS? WHY SWIFT? WHY BREEZE? WHY BREEZE?
  • 33. ANDREA SCUDERI - SENIOR IOS ENGINEER @ JUST EAT TAKEAWAY STAY IN TOUCH! ▸ Twitter: @andreascuderi13 ▸ Linkedin: https://www.linkedin.com/in/andreascuderi/ ▸ Medium: https://medium.com/@andreascuderi73