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

Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 

Recently uploaded (20)

Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 

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