This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create a Role giving our Lambda access. | |
let policy: aws.iam.PolicyDocument = { /* Redacted for brevity */ }; | |
let role = new aws.iam.Role("lambda-role", { | |
assumeRolePolicy: JSON.stringify(policy), | |
}); | |
let fullAccess = new aws.iam.RolePolicyAttachment("lambda-access", { | |
role: role, | |
policyArn: aws.iam.AWSLambdaFullAccess, | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as aws from "@pulumi/aws"; | |
// A DynamoDB table with a single primary key | |
let counterTable = new aws.dynamodb.Table("urls", { | |
name: "urls", | |
attributes: [ | |
{ name: "name", type: "S" }, | |
], | |
hashKey: "name", | |
readCapacity: 1, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let workflow wishlist = async { | |
let! matches = | |
wishlist.Wishes | |
|> List.map findMatchingGift | |
|> Async.Parallel | |
let gift = pickGift (List.concat matches) | |
let reservation = { Kid = wishlist.Kid; Product = gift } | |
do! reserve reservation |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[<FunctionName("FindMatchingGift")>] | |
let FindMatchingGift([<ActivityTrigger>] wish) = | |
Activity.run findMatchingGiftActivity wish | |
[<FunctionName("PickGift")>] | |
let PickGift([<ActivityTrigger>] matches) = | |
Activity.run pickGiftActivity matches | |
[<FunctionName("Reserve")>] | |
let Reserve([<ActivityTrigger>] wish) = |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let workflow wishlist = orchestrator { | |
let! matches = | |
wishlist.Wishes | |
|> List.map (Activity.call findMatchingGiftActivity) | |
|> Activity.all | |
let! gift = Activity.call pickGiftActivity (List.concat matches) | |
let reservation = { Kid = wishlist.Kid; Product = gift } | |
do! Activity.call reserveActivity reservation |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let findMatchingGiftActivity = Activity.defineAsync "FindMatchingGift" findMatchingGift | |
let pickGiftActivity = Activity.define "PickGift" pickGift | |
let reserveActivity = Activity.defineAsync "Reserve" reserve |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1. Simple sequencing of activities | |
let Run([<OrchestrationTrigger>] context: DurableOrchestrationContext) = task { | |
let! hello1 = context.CallActivityAsync<string>("E1_SayHello", "Tokyo") | |
let! hello2 = context.CallActivityAsync<string>("E1_SayHello", "Seattle") | |
let! hello3 = context.CallActivityAsync<string>("E1_SayHello", "London") | |
return [hello1; hello2; hello3] | |
} | |
// 2. Parallel calls snippet | |
let tasks = Array.map (fun f -> context.CallActivityAsync<int64>("E2_CopyFileToBlob", f)) files |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// WishList -> Async<Reservation> | |
let workflow (wishlist: WishList) = async { | |
// 1. Find matches for each wish | |
let! matches = | |
wishlist.Wishes | |
|> List.map findMatchingGift | |
|> Async.Parallel | |
// 2. Pick one product from the combined list of matches |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Reservation -> Async<unit> | |
let reserve (reservation: Reservation) = async { | |
// Call Santa's Archive of Products | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Match list -> Product | |
let pickGift (candidates: Match list) = | |
candidates | |
|> List.sortByDescending (fun x -> x.Confidence) | |
|> List.head | |
|> (fun x -> x.Product) |