techdays 2017 - creating real life serverless solutions with azure functions
TRANSCRIPT
![Page 1: TechDays 2017 - Creating real life serverless solutions with azure functions](https://reader036.vdocuments.us/reader036/viewer/2022062412/5a67591f7f8b9a8a378b46d7/html5/thumbnails/1.jpg)
![Page 2: TechDays 2017 - Creating real life serverless solutions with azure functions](https://reader036.vdocuments.us/reader036/viewer/2022062412/5a67591f7f8b9a8a378b46d7/html5/thumbnails/2.jpg)
![Page 3: TechDays 2017 - Creating real life serverless solutions with azure functions](https://reader036.vdocuments.us/reader036/viewer/2022062412/5a67591f7f8b9a8a378b46d7/html5/thumbnails/3.jpg)
![Page 4: TechDays 2017 - Creating real life serverless solutions with azure functions](https://reader036.vdocuments.us/reader036/viewer/2022062412/5a67591f7f8b9a8a378b46d7/html5/thumbnails/4.jpg)
servers
![Page 5: TechDays 2017 - Creating real life serverless solutions with azure functions](https://reader036.vdocuments.us/reader036/viewer/2022062412/5a67591f7f8b9a8a378b46d7/html5/thumbnails/5.jpg)
Like PaaS
![Page 6: TechDays 2017 - Creating real life serverless solutions with azure functions](https://reader036.vdocuments.us/reader036/viewer/2022062412/5a67591f7f8b9a8a378b46d7/html5/thumbnails/6.jpg)
“If your PaaS can efficiently start instances in 20ms that run for half a second, then call it serverless.”Adrian Cockcroft - VP Cloud Architecture Strategy AWS
![Page 7: TechDays 2017 - Creating real life serverless solutions with azure functions](https://reader036.vdocuments.us/reader036/viewer/2022062412/5a67591f7f8b9a8a378b46d7/html5/thumbnails/7.jpg)
Keep It Small and Simple
![Page 8: TechDays 2017 - Creating real life serverless solutions with azure functions](https://reader036.vdocuments.us/reader036/viewer/2022062412/5a67591f7f8b9a8a378b46d7/html5/thumbnails/8.jpg)
![Page 9: TechDays 2017 - Creating real life serverless solutions with azure functions](https://reader036.vdocuments.us/reader036/viewer/2022062412/5a67591f7f8b9a8a378b46d7/html5/thumbnails/9.jpg)
URL Minification
![Page 10: TechDays 2017 - Creating real life serverless solutions with azure functions](https://reader036.vdocuments.us/reader036/viewer/2022062412/5a67591f7f8b9a8a378b46d7/html5/thumbnails/10.jpg)
GET minified URL redirect
CREATE minified URL
![Page 11: TechDays 2017 - Creating real life serverless solutions with azure functions](https://reader036.vdocuments.us/reader036/viewer/2022062412/5a67591f7f8b9a8a378b46d7/html5/thumbnails/11.jpg)
CosmosDB
![Page 12: TechDays 2017 - Creating real life serverless solutions with azure functions](https://reader036.vdocuments.us/reader036/viewer/2022062412/5a67591f7f8b9a8a378b46d7/html5/thumbnails/12.jpg)
Oh yeah!
![Page 13: TechDays 2017 - Creating real life serverless solutions with azure functions](https://reader036.vdocuments.us/reader036/viewer/2022062412/5a67591f7f8b9a8a378b46d7/html5/thumbnails/13.jpg)
![Page 14: TechDays 2017 - Creating real life serverless solutions with azure functions](https://reader036.vdocuments.us/reader036/viewer/2022062412/5a67591f7f8b9a8a378b46d7/html5/thumbnails/14.jpg)
Web App CosmosDB
![Page 15: TechDays 2017 - Creating real life serverless solutions with azure functions](https://reader036.vdocuments.us/reader036/viewer/2022062412/5a67591f7f8b9a8a378b46d7/html5/thumbnails/15.jpg)
![Page 16: TechDays 2017 - Creating real life serverless solutions with azure functions](https://reader036.vdocuments.us/reader036/viewer/2022062412/5a67591f7f8b9a8a378b46d7/html5/thumbnails/16.jpg)
CosmosDB
GET
POST
![Page 17: TechDays 2017 - Creating real life serverless solutions with azure functions](https://reader036.vdocuments.us/reader036/viewer/2022062412/5a67591f7f8b9a8a378b46d7/html5/thumbnails/17.jpg)
CosmosDB
GET
POST
Azure cacheUPDATE Change
Feed
![Page 18: TechDays 2017 - Creating real life serverless solutions with azure functions](https://reader036.vdocuments.us/reader036/viewer/2022062412/5a67591f7f8b9a8a378b46d7/html5/thumbnails/18.jpg)
CosmosDB
GET
POST
Azure cacheUPDATE
ChangeFeed
Queue TRIGGER
![Page 19: TechDays 2017 - Creating real life serverless solutions with azure functions](https://reader036.vdocuments.us/reader036/viewer/2022062412/5a67591f7f8b9a8a378b46d7/html5/thumbnails/19.jpg)
CosmosDB
GET
POST
![Page 20: TechDays 2017 - Creating real life serverless solutions with azure functions](https://reader036.vdocuments.us/reader036/viewer/2022062412/5a67591f7f8b9a8a378b46d7/html5/thumbnails/20.jpg)
Bindings are your friend
![Page 21: TechDays 2017 - Creating real life serverless solutions with azure functions](https://reader036.vdocuments.us/reader036/viewer/2022062412/5a67591f7f8b9a8a378b46d7/html5/thumbnails/21.jpg)
"bindings": [
{
"type": "httpTrigger",
"route": "{slug}",
"methods": [
"get"
],
"authLevel": "anonymous",
"name": "req"
}
],
Function, User, System & Admin
![Page 22: TechDays 2017 - Creating real life serverless solutions with azure functions](https://reader036.vdocuments.us/reader036/viewer/2022062412/5a67591f7f8b9a8a378b46d7/html5/thumbnails/22.jpg)
"bindings": [
{
"name": “minifiedUrl",
"type": "documentDB",
"databaseName": “MinifyRepository",
"collectionName": “MinifiedUrls",
"createIfNotExists": true,
"connection": “CosmosDbConnection",
"direction": "out"
}
],
![Page 23: TechDays 2017 - Creating real life serverless solutions with azure functions](https://reader036.vdocuments.us/reader036/viewer/2022062412/5a67591f7f8b9a8a378b46d7/html5/thumbnails/23.jpg)
Don’t write JSON
![Page 24: TechDays 2017 - Creating real life serverless solutions with azure functions](https://reader036.vdocuments.us/reader036/viewer/2022062412/5a67591f7f8b9a8a378b46d7/html5/thumbnails/24.jpg)
![Page 25: TechDays 2017 - Creating real life serverless solutions with azure functions](https://reader036.vdocuments.us/reader036/viewer/2022062412/5a67591f7f8b9a8a378b46d7/html5/thumbnails/25.jpg)
Where to put the code
![Page 26: TechDays 2017 - Creating real life serverless solutions with azure functions](https://reader036.vdocuments.us/reader036/viewer/2022062412/5a67591f7f8b9a8a378b46d7/html5/thumbnails/26.jpg)
Existing patterns & principles still apply!
![Page 27: TechDays 2017 - Creating real life serverless solutions with azure functions](https://reader036.vdocuments.us/reader036/viewer/2022062412/5a67591f7f8b9a8a378b46d7/html5/thumbnails/27.jpg)
private readonly ICosmosClient cosmosClient;
public CreateUrlHandler()
{
this.cosmosClient = new CosmosClient();
}
public CreateUrlHandler(ICosmosClient cosmosClient)
{
this.cosmosClient = cosmosClient;
}
![Page 28: TechDays 2017 - Creating real life serverless solutions with azure functions](https://reader036.vdocuments.us/reader036/viewer/2022062412/5a67591f7f8b9a8a378b46d7/html5/thumbnails/28.jpg)
![Page 29: TechDays 2017 - Creating real life serverless solutions with azure functions](https://reader036.vdocuments.us/reader036/viewer/2022062412/5a67591f7f8b9a8a378b46d7/html5/thumbnails/29.jpg)
CosmosDB
GET
POST
![Page 30: TechDays 2017 - Creating real life serverless solutions with azure functions](https://reader036.vdocuments.us/reader036/viewer/2022062412/5a67591f7f8b9a8a378b46d7/html5/thumbnails/30.jpg)
![Page 31: TechDays 2017 - Creating real life serverless solutions with azure functions](https://reader036.vdocuments.us/reader036/viewer/2022062412/5a67591f7f8b9a8a378b46d7/html5/thumbnails/31.jpg)
![Page 32: TechDays 2017 - Creating real life serverless solutions with azure functions](https://reader036.vdocuments.us/reader036/viewer/2022062412/5a67591f7f8b9a8a378b46d7/html5/thumbnails/32.jpg)
[FunctionName("Get")]
public static async Task<HttpResponseMessage> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "{slug}")]
HttpRequestMessage req,
string slug,
TraceWriter log)
{
var getUrl = new GetUrlHandler();
var minifiedUrl = await getUrl.Execute(slug);
if (minifiedUrl == null)
{
return req.CreateErrorResponse(HttpStatusCode.NotFound,
$"Minified value `{slug}` is not found.");
}
var response = req.CreateResponse(HttpStatusCode.Redirect);
response.Headers.Location = new Uri(minifiedUrl.FullUrl);
return response;
}
![Page 33: TechDays 2017 - Creating real life serverless solutions with azure functions](https://reader036.vdocuments.us/reader036/viewer/2022062412/5a67591f7f8b9a8a378b46d7/html5/thumbnails/33.jpg)
public static class Create
{
[FunctionName("Create")]
public static HttpResponseMessage Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "create")]
HttpRequestMessage req,
[DocumentDB("datbaseName", "collectionName",
PartitionKey = "MinifiedUrls",
CreateIfNotExists = true,
ConnectionStringSetting = "minifiedUrlConnectionString")]
out dynamic minifiedUrl,
TraceWriter log)
{
string jsonContent = req.Content.ReadAsStringAsync().Result;
var data = JsonConvert.DeserializeObject<MinifiedUrl>(jsonContent);
var create = new CreateUrlHandler();
minifiedUrl = create.Execute(data);
return req.CreateResponse(HttpStatusCode.Created,
$"api/{data.MinifiedSlug}");
}
}
![Page 34: TechDays 2017 - Creating real life serverless solutions with azure functions](https://reader036.vdocuments.us/reader036/viewer/2022062412/5a67591f7f8b9a8a378b46d7/html5/thumbnails/34.jpg)
![Page 35: TechDays 2017 - Creating real life serverless solutions with azure functions](https://reader036.vdocuments.us/reader036/viewer/2022062412/5a67591f7f8b9a8a378b46d7/html5/thumbnails/35.jpg)
Easy mode
![Page 36: TechDays 2017 - Creating real life serverless solutions with azure functions](https://reader036.vdocuments.us/reader036/viewer/2022062412/5a67591f7f8b9a8a378b46d7/html5/thumbnails/36.jpg)
![Page 37: TechDays 2017 - Creating real life serverless solutions with azure functions](https://reader036.vdocuments.us/reader036/viewer/2022062412/5a67591f7f8b9a8a378b46d7/html5/thumbnails/37.jpg)
![Page 38: TechDays 2017 - Creating real life serverless solutions with azure functions](https://reader036.vdocuments.us/reader036/viewer/2022062412/5a67591f7f8b9a8a378b46d7/html5/thumbnails/38.jpg)
master branch
to production
![Page 39: TechDays 2017 - Creating real life serverless solutions with azure functions](https://reader036.vdocuments.us/reader036/viewer/2022062412/5a67591f7f8b9a8a378b46d7/html5/thumbnails/39.jpg)
Pro mode
![Page 40: TechDays 2017 - Creating real life serverless solutions with azure functions](https://reader036.vdocuments.us/reader036/viewer/2022062412/5a67591f7f8b9a8a378b46d7/html5/thumbnails/40.jpg)
![Page 41: TechDays 2017 - Creating real life serverless solutions with azure functions](https://reader036.vdocuments.us/reader036/viewer/2022062412/5a67591f7f8b9a8a378b46d7/html5/thumbnails/41.jpg)
![Page 42: TechDays 2017 - Creating real life serverless solutions with azure functions](https://reader036.vdocuments.us/reader036/viewer/2022062412/5a67591f7f8b9a8a378b46d7/html5/thumbnails/42.jpg)
Check if you use slots
Point to the correct package
![Page 43: TechDays 2017 - Creating real life serverless solutions with azure functions](https://reader036.vdocuments.us/reader036/viewer/2022062412/5a67591f7f8b9a8a378b46d7/html5/thumbnails/43.jpg)
![Page 44: TechDays 2017 - Creating real life serverless solutions with azure functions](https://reader036.vdocuments.us/reader036/viewer/2022062412/5a67591f7f8b9a8a378b46d7/html5/thumbnails/44.jpg)
![Page 45: TechDays 2017 - Creating real life serverless solutions with azure functions](https://reader036.vdocuments.us/reader036/viewer/2022062412/5a67591f7f8b9a8a378b46d7/html5/thumbnails/45.jpg)
![Page 46: TechDays 2017 - Creating real life serverless solutions with azure functions](https://reader036.vdocuments.us/reader036/viewer/2022062412/5a67591f7f8b9a8a378b46d7/html5/thumbnails/46.jpg)
https://my.jdv.li/api/minifiedurl
or
https://my.jdv.li/minifiedurl
![Page 47: TechDays 2017 - Creating real life serverless solutions with azure functions](https://reader036.vdocuments.us/reader036/viewer/2022062412/5a67591f7f8b9a8a378b46d7/html5/thumbnails/47.jpg)
{
"$schema": "http://json.schemastore.org/proxies",
"proxies": {
"getminifiedredirect": {
"matchCondition": {
"methods": [ "GET" ],
"route": "/{slug}"
},
"backendUri": "https://%WEBSITE_HOSTNAME%/api/{slug}"
}
}
}
Matching conditions