<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[dispatchframework - Medium]]></title>
        <description><![CDATA[Dispatch framework is a batteries-included open source function service - Medium]]></description>
        <link>https://medium.com/dispatchframework?source=rss----ee978f2747ea---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>dispatchframework - Medium</title>
            <link>https://medium.com/dispatchframework?source=rss----ee978f2747ea---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 16:11:04 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/dispatchframework" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Dispatch — A Multi-Tenant FaaS]]></title>
            <link>https://medium.com/dispatchframework/dispatch-a-multi-tenant-faas-faf8f485ffe1?source=rss----ee978f2747ea---4</link>
            <guid isPermaLink="false">https://medium.com/p/faf8f485ffe1</guid>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[vmware]]></category>
            <category><![CDATA[openfaas]]></category>
            <dc:creator><![CDATA[Sabari Murugesan]]></dc:creator>
            <pubDate>Wed, 04 Jul 2018 00:31:38 GMT</pubDate>
            <atom:updated>2018-07-06T16:57:05.442Z</atom:updated>
            <content:encoded><![CDATA[<p>We are in a world where it’s hard to imagine any enterprise service not being a multi-tenant system. From your IaaS layer to container registries, companies like to easily onboard users and teams, enforce access policies and quotas all while operating as few instances of a service as possible. Why should your FaaS (Function as a Service) offering be any different?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*q5hpAj8zJto0My70" /><figcaption>Photo by <a href="https://unsplash.com/@viktorkern?utm_source=medium&amp;utm_medium=referral">Viktor Kern</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>With the latest <a href="https://vmware.github.io/dispatch/2018/07/03/v0-1-20-release.html">release</a> of <a href="http://dispatchframework.io/">Dispatch</a> — an open source serverless framework, we are closer than ever to help you build a multi-tenant FaaS. In this blog post, we will explore how to create different tenants in Dispatch, add users to it and run functions. We will also discuss some shortcomings and how we are planning to address them in the future. To keep it simple, we will assume Dispatch is configured with <a href="https://www.openfaas.com/">OpenFaaS</a> as the FaaS engine and uses <a href="https://developers.google.com/identity/protocols/OpenIDConnect">Google Identity Platform</a> as the OpenID Connect provider.</p><p>But before we talk about multi-tenancy, it’s important to understand about authentication &amp; authorization in Dispatch, as they form the core principles upon which multi-tenancy can be designed.</p><h3>Authentication</h3><blockquote><strong>Dispatch does not manage your user accounts</strong></blockquote><p>Dispatch does not manage user accounts on its own, in other words, there is no notion of adding accounts with a specific username/password to Dispatch using an API call. This is because:</p><ul><li>There is seldom just an Alice and Bob in a team or only an admin/root user in a corporate system. Usually there is a user directory with LDAP authentication or other Identity Management solutions. It’s cumbersome (and error-prone) for a service to manage large user sets and keep them in sync with directories.</li><li>Decreasing trust of applications that store your enterprise credentials. How familiar is this prompt <em>“Please input your AD username/password”</em> on an internal service portal? Yet we have no idea how our credentials are stored and managed.</li><li>Lastly, single sign-on is here to stay whether you like being hauled into multiple portals via redirects or not.</li></ul><p>Hence, Dispatch does not manage user accounts or store credentials but integrates well with <a href="http://openid.net/connect/">OpenID Connect</a> providers like Google Identity Platform, <a href="https://www.vmware.com/products/workspace-one/identity-manager.html">vIDM</a>, <a href="https://auth0.com/">Auth0</a>, or <a href="https://github.com/coreos/dex">Dex</a> that provides session authentication over a well-established standard.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/375/1*uiLnn-fqgbdTc4t2ymskEw.png" /></figure><p>But wait, what about automation or integration accounts running in a non-browser environment? Dispatch has the concept of <a href="https://vmware.github.io/dispatch/documentation/guides/setup-service-acccount-authentication">service accounts</a> for such needs. These are locally managed accounts secured with RSA keys.</p><h3>Authorization</h3><blockquote><strong>Policy Driven</strong></blockquote><p>Authorization in Dispatch is enforced by policies that describe the access rights of a user/group. Before a user can login to Dispatch, we need to create policies that grant privileges on one or more resources like functions, images etc. Within a single tenant, users can have different privileges based on their functional role. Typically, an administrator will have access to add <em>base-images and images</em> — these are secure container images with the runtime &amp; dependencies needed for executing a function. A Developer, on the contrary, can build functions off of an image provided by an administrator. On the other hand, a service-account used for monitoring resource usage could just have read-only privileges. You get the point!</p><p>A Sample policy in Dispatch described in JSON format:</p><pre>[<br>    {<br>        &quot;createdTime&quot;: 1530561893,<br>        &quot;global&quot;: true,<br>        &quot;id&quot;: &quot;f8d0b220-26b0-4de8-b281-1066156690a6&quot;,<br>        &quot;kind&quot;: &quot;Policy&quot;,<br>        &quot;modifiedTime&quot;: 1530561893,<br>        &quot;name&quot;: &quot;default-policy&quot;,<br>        &quot;rules&quot;: [<br>            {<br>                &quot;actions&quot;: [<br>                    &quot;*&quot;<br>                ],<br>                &quot;resources&quot;: [<br>                    &quot;images,base-images&quot;<br>                ],<br>                &quot;subjects&quot;: [<br>                    &quot;abc@example.com&quot;<br>                ]<br>            }<br>        ],<br>        &quot;status&quot;: &quot;READY&quot;<br>    }<br>]</pre><h3>Multi-Tenancy</h3><p>Okay, let’s get to the point of this blog. Tenants in Dispatch are called <strong>Organizations</strong>. You can create organizations and setup policies under each to onboard users/teams. In this example, we will create organizations representing two fictitious <em>frontend </em>&amp; <em>backend </em>teams of a typical product. We will then add admin policies, user policies and then let the users create and run functions.</p><h4><strong>Creating a New Organization</strong></h4><p>After installing dispatch based on the steps <a href="https://vmware.github.io/dispatch/documentation/guides/setup-authentication">detailed here</a>, you are now logged in to Dispatch under the default organization ‘<em>dispatch</em>’ with a user that has god-privileges or in other words a <em>super-admin</em> user. You can use this account to setup other organizations and policies.</p><p>Ensure you have the required privileges by listing existing organizations:</p><pre>$ dispatch iam get organizations</pre><pre>    NAME   |         CREATED DATE<br>----------------------------------------<br>  dispatch | Mon Jul  2 13:04:50 PDT 2018</pre><p>Now, create two new organizations <em>frontend-team</em> &amp; <em>backend-team</em> with:</p><pre>$ dispatch iam create organization frontend-team<br>Created organization: frontend-team</pre><pre>$ dispatch iam create organization backend-team<br>Created organization: backend-team</pre><h4><strong>Adding Admin Policies</strong></h4><p>We now add two policies granting admin privileges to specific users of the teams. Since we configured Google Identity Platform as the OpenID connect provider, we use the email address associated with the admin users while setting up the policy.</p><p>Note the usage of the--organization flag to denote the tenant under which the policy must be created. This works since we are logged in as the super-admin user that has privileges across all organizations.</p><pre>$ dispatch iam create policy frontend-admin \<br>--subject adm.frontend.dispatch@gmail.com \<br>--action &quot;*&quot; --resource &quot;*&quot; \<br>--organization frontend-team</pre><pre>Created policy: frontend-admin</pre><pre>$ dispatch iam create policy backend-admin \<br>--subject adm.backend.dispatch@gmail.com \<br>--action &quot;*&quot; --resource &quot;*&quot; \<br>--organization backend-team</pre><pre>Created policy: backend-admin</pre><h4><strong>Login as the Frontend Admin</strong></h4><p>Let’s logout as the super-admin user and login as the <em>admin</em> of the frontend team.</p><pre>$ dispatch logout<br>You have successfully logged out</pre><pre>$ dispatch login --organization frontend-team</pre><p>Since we configured Google Identity Platform as the OpenID Connect provider, dispatch login command will open up the default browser and prompt the user to sign-in to their google account. In this case, since we are logging in as the <em>frontend admin, </em>let’s choose the corresponding account.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/541/1*_SYpdxlB1Jvn0RNyQw_4iA.png" /></figure><p>Upon entering the credentials for the <em>frontend admin</em> account, you will now notice some redirections related to <em>OAuth2 Authorization Code Grant</em> and then the following message on the browser appears:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/385/1*ej52Jqo1zlxZa8gnJliTog.png" /></figure><p>At this point, your CLI has received a cookie for the session and you are logged-in as the <em>frontend admin</em> to the <em>frontend team</em> organization.</p><p>Create base-images &amp; images for use by the team members. As mentioned above, these images are secure container images that provide the runtime and dependencies for your function code.</p><pre>$ dispatch create seed-images</pre><pre>Created BaseImage: nodejs-base<br>Created BaseImage: python3-base<br>Created BaseImage: powershell-base<br>Created BaseImage: java-base<br>Created Image: nodejs<br>Created Image: python3<br>Created Image: powershell<br>Created Image: java</pre><h4><strong>Add User Policies for The Frontend Team</strong></h4><p>The following commands adds policies for the developers of the frontend-team restricting their access to creating &amp; executing functions. Since images are fundamental to creating functions, we provide the users with read-access to images.</p><pre># Allow CRUD on functions and related resources<br>$ dispatch iam create policy dev-policy-crud \<br>--subject dev1.frontend.dispatch@gmail.com \<br>--subject dev2.frontend.dispatch@gmail.com \<br>--action &quot;*&quot; \<br>--resource function,runs,secret,api</pre><pre>Created policy: dev-policy-crud</pre><pre># Read-Only access on Image resources<br>$ dispatch iam create policy dev-policy-read \<br>--subject dev1.frontend.dispatch@gmail.com \<br>--subject dev2.frontend.dispatch@gmail.com \<br>--action get \<br>--resource image,baseimage</pre><pre>Created policy: dev-policy-read</pre><h4><strong>Login as Frontend Developer</strong></h4><pre>$ dispatch logout<br>You have successfully logged out</pre><pre>$ dispatch login --organization frontend-team</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/559/1*yXSx8oHI6kSHTKxnRA5m3Q.png" /></figure><h4><strong>Create a Function as the Frontend Developer</strong></h4><pre>$ cat &gt; /tmp/node-hello.js &lt;&lt;EOF<br>module.exports = function (context, params) {<br>    let name = &quot;Noone&quot;;<br>    if (params.name) {<br>        name = params.name;<br>    }<br>    let place = &quot;Nowhere&quot;;<br>    if (params.place) {<br>        place = params.place;<br>    }<br>    return {myField: &#39;Hello, &#39; + name + &#39; from &#39; + place + &#39; - Yours, nodejs!&#39;}<br>};<br>EOF</pre><pre>$ dispatch create function --image=nodejs node-hello-js /tmp/node-hello.js<br>Created function: node-hello-js</pre><h4><strong>Create an API for the nodejs function</strong></h4><p>Dispatch has an in-built API Gateway (powered by <a href="https://konghq.com/">Kong</a>) that supports the creation of API’s that then point to your function.</p><pre>$ dispatch create api frontend-hello-js node-hello-js --path /hello --cors<br>Created api: frontend-hello-js</pre><h4><strong>Execute the Function via the API</strong></h4><p>Once the API is created, you can access it through the Dispatch’s API Gateway. For this blog, the API Gateway has been setup to use the host <a href="https://orgdemo.dispatchframework.io/http://orgdemo.dispatchframework.io/">orgdemo.dispatchframework.io</a>. Hence, all the API paths can be accessed at https://orgdemo.dispatchframework.io/&lt;org_name/&lt;path&gt;. Thus, the API created above can be accessed at the following URL:</p><pre>$ curl <a href="https://orgdemo.dispatchframework.io/frontend-team/hello">https://orgdemo.dispatchframework.io/frontend-team/hello</a></pre><pre>{&quot;myField&quot;:&quot;Hello, Noone from Nowhere - Yours, nodejs!&quot;}</pre><h4>Repeat steps for the Backend Team</h4><p>Let’s execute similar steps as before for the <em>backend team</em>. For brevity, let’s not discuss each step in detail.</p><pre>############################<br># Login as Backend Admin<br>############################</pre><pre>$ dispatch login --organization backend-team<br># Choose the `Backend Admin`Account in the Google Authentication Prompt</pre><pre># Allow CRUD on functions and related resources<br>$ dispatch iam create policy dev-policy-crud \<br>--subject dev1.backend.dispatch@gmail.com \<br>--subject dev2.backend.dispatch@gmail.com \<br>--action &quot;*&quot; \<br>--resource function,runs,secret,api<br>Created policy: dev-policy-crud</pre><pre># Read-Only access on Image resources<br>$ dispatch iam create policy dev-policy-read \<br>--subject dev1.backend.dispatch@gmail.com \<br>--subject dev2.backend.dispatch@gmail.com \<br>--action get \<br>--resource image,baseimage<br>Created policy: dev-policy-read</pre><pre>$ dispatch logout<br>You have successfully logged out</pre><pre>############################<br># Login as Backend Developer<br>############################</pre><pre>$ dispatch login --organization backend-team<br># Choose the `Backend Developer` Account in the Google Authentication Prompt</pre><pre>###################################################<br># Create a Python Function as the Backend Developer<br>###################################################</pre><pre>$ cat &gt; /tmp/python_hello.py &lt;&lt;EOF<br>def handle(ctx, payload):<br>    name = &quot;Noone&quot;<br>    place = &quot;Nowhere&quot;<br>    if payload:<br>        name = payload.get(&quot;name&quot;, name)<br>        place = payload.get(&quot;place&quot;, place)<br>    return {&quot;myField&quot;: &quot;Hello, %s from %s - Yours, python3!&quot; % (name, place)}<br>EOF</pre><pre>$ dispatch create function --image=python3 python-hello /tmp/python_hello.py</pre><pre>#######################################<br># Create an API for the python function<br>#######################################</pre><pre>$ dispatch create api backend-hello-python python-hello --path /hello<br>Created api: backend-hello-python</pre><h4>Execute the Backend Team’s function via the API</h4><pre>$ curl <a href="https://orgdemo.dispatchframework.io/frontend-team/hello-js">https://orgdemo.dispatchframework.io/backend-team/hello</a></pre><pre>{&quot;myField&quot;:&quot;Hello, Noone from Nowhere - Yours, python3!&quot;}</pre><h3>Future Work</h3><p>We are at the whiteboard jotting designs (and doodling..) to enhance the multi-tenancy experience in many ways. Some of the tasks that are in the pipeline are:</p><ul><li>LDAP groups/OIDC groups claim support</li><li>Support for defining roles in policies</li><li>Automate SSL cert generation per organization for API endpoints</li><li>Support image registries per organization</li></ul><h3>Conclusion</h3><p>With the <a href="https://vmware.github.io/dispatch/2018/07/03/v0-1-20-release.html">latest version</a> of Dispatch, it’s now possible to build a Multi-Tenant FaaS service in your enterprise and onboard your teams and developers. Isn’t that <strong>FaaScinating</strong>?</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=faf8f485ffe1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/dispatchframework/dispatch-a-multi-tenant-faas-faf8f485ffe1">Dispatch — A Multi-Tenant FaaS</a> was originally published in <a href="https://medium.com/dispatchframework">dispatchframework</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Tweeting Images by Dispatch with AWS Cloud Events]]></title>
            <link>https://medium.com/dispatchframework/tweeting-images-by-dispatch-with-aws-cloud-events-1ec9066701cd?source=rss----ee978f2747ea---4</link>
            <guid isPermaLink="false">https://medium.com/p/1ec9066701cd</guid>
            <category><![CDATA[cloudevents]]></category>
            <category><![CDATA[dispatchframework]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Zimeng Yang]]></dc:creator>
            <pubDate>Thu, 14 Jun 2018 22:17:38 GMT</pubDate>
            <atom:updated>2018-06-22T23:44:09.221Z</atom:updated>
            <content:encoded><![CDATA[<p>Dispatch supports cloud events, and you can also create your own event driver to trigger functions. Let’s create something to show off those features.</p><p>Here are the demo workflows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*WuQRLIxHaTI6HhKdkbFw3A.png" /></figure><p>User needs to grant secrets to Dispatch event driver, and driver itself will create required aws resources and establish connections. Once user uploads image to s3 bucket, event driver will fetch the event and send it to Dispatch. Then Dispatch will invoke function to watermark the image and tweet it out.</p><h3>Prerequisites</h3><ol><li>A running Dispatch instance (<a href="https://vmware.github.io/dispatch/documentation/guides/quickstart">quickstart</a>)</li><li>Dispatch CLI (<a href="https://github.com/vmware/dispatch/releases/latest">latest release</a>)</li><li><a href="https://aws.amazon.com/console/">AWS account</a> and <a href="https://apps.twitter.com/">Twitter Apps</a></li></ol><h3>Setup AWS S3 Bucket And CloudTrail</h3><p>The very first thing we need is a s3 bucket. Follow this <a href="https://docs.aws.amazon.com/quickstarts/latest/s3backup/step-1-create-bucket.html">instructions</a> to create a s3 bucket. And take a note of <strong>region</strong> and <strong>bucket name</strong>.</p><p>Besides, we also need to create CloudTrail which required by aws for events to be caught. Follow this <a href="https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-create-a-trail-using-the-console-first-time.html">instructions</a> to setup CloudTrail for your s3 bucket. And make sure that in Data Events section, add the s3 bucket you just created. If you want to upload the images to some specific folder in s3 bucket, for example images folder, remember to put images in <strong>prefix</strong> for Data Events.</p><p>If CloudTrail was setup properly, you should see Object-level logging is enabled in your s3 bucket -&gt; Properties.</p><h3>Setup Dispatch Eventdriver</h3><p>What’s next? We need an event driver to fetch aws s3 image uploading event and send it to Dispatch for later processing.</p><h4>Create AWS Secret</h4><p>In order to connect to AWS services, we need to retrieve the aws secrets. Put them in aws-secret.json:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9e8445573fdf57a467badaa24be7e3cf/href">https://medium.com/media/9e8445573fdf57a467badaa24be7e3cf/href</a></iframe><p>Then, create a secret named aws:</p><pre>$ dispatch create secret aws aws-secret.json<br>Created secret: aws</pre><h4>Create Event-driver-type</h4><p>You can find a prebuilt event driver image in Docker Hub <strong>dispatchframework/dispatch-events-aws. </strong>Let’s create event-driver-type using that prebuilt image:</p><pre>$ dispatch create eventdrivertype aws dispatchframework/dispatch-events-aws:latest<br>Created event driver type: aws</pre><p>Or, if you prefer to build image yourself. The <a href="https://github.com/dispatchframework/dispatch-events-aws">event driver repo</a> contains all driver codes and Dockerfile:</p><pre>$ docker build -t dispatch-events-aws:latest .</pre><h4>Create Event Driver</h4><p>Event driver will need some event patterns for CloudWatch rules, details can be found <a href="https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/CloudWatchEventsandEventPatterns.html">here</a>. We will use this template for our demo:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/323b4bf592aea5dd8544b602c6dd5ec2/href">https://medium.com/media/323b4bf592aea5dd8544b602c6dd5ec2/href</a></iframe><p>And make sure to replace <strong>&lt;bucket-name&gt;</strong> section to the s3 bucket you just created.</p><p>Now, we have everything we need to create the real event driver:</p><pre>$ dispatch create eventdriver aws --secret aws --set clean-up --set region=&quot;us-west-2&quot; --set event-patterns=&#39;[<br>    {<br>        &quot;source&quot;: [<br>            &quot;aws.s3&quot;<br>        ],<br>        &quot;detail-type&quot;: [<br>            &quot;AWS API Call via CloudTrail&quot;<br>        ],<br>        &quot;detail&quot;: {<br>            &quot;eventSource&quot;: [<br>                &quot;s3.amazonaws.com&quot;<br>            ],<br>            &quot;eventName&quot;: [<br>                &quot;PutObject&quot;<br>            ],<br>            &quot;requestParameters&quot;: {<br>                &quot;bucketName&quot;: [<br>                    &quot;dispatch-events-aws-demo&quot;<br>                ]<br>            }<br>        }<br>    }<br>]&#39;</pre><p>Some explanations:</p><ul><li>We are creating an event driver of type <strong>aws</strong>.</li><li>We need the <strong>aws</strong> secret to talk to aws services.</li><li>We want to <strong>clean-up</strong> the aws resources after event driver shuts down.</li><li>We use <strong>us-west-2</strong> as region, change this to your aws region if different.</li><li>We define <strong>event-patterns</strong> which is a json array string, if you have more event patterns, put them together in a json-array-style. Examples are <a href="https://github.com/dispatchframework/dispatch-events-aws/blob/master/event-patterns-example.json">here</a>. And the bucket name we used here is dispatch-events-aws-demo. Change it to your bucket.</li></ul><p>If everything goes well, we should now see the event driver is ready. That means the event driver finishs initialization of required resources, starts fetching events from aws SQS and sending them to Dispatch.</p><h3>Setup Dispatch Function</h3><p>Now we have a running event driver that is sending events to Dispatch, but we don’t have the function to process events yet. So, let’s go to create a function to watermark image and publish it to Twitter.</p><h4>Create Twitter Secret</h4><p>To tweet something, we need credentials from Twitter Apps, create a new twitter app and get the credentials. Put them in twitter-secret.json:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d347f0986d3b82f63d8a4cf7eca23bc2/href">https://medium.com/media/d347f0986d3b82f63d8a4cf7eca23bc2/href</a></iframe><p>Then, create a secret named twitter:</p><pre>$ dispatch create secret twitter twitter-secret.json<br>Created secret: twitter</pre><h4>Create Base Image and Image</h4><p>Before creating the function, we need to create base image and image first.</p><pre>$ dispatch create base-image python3-base dispatchframework/python3-base:0.0.7 --language python3</pre><p>After base-image is ready (check by dispatch get base-image), create image:</p><pre>$ dispatch create image python3-twitter python3-base --runtime-deps requirements.txt</pre><p>In requirements.txt, we specify the runtime dependencies for our function:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c730493e2d634d9ef1e91f64f556fe93/href">https://medium.com/media/c730493e2d634d9ef1e91f64f556fe93/href</a></iframe><h4>Create Function</h4><p>Next comes to the real function creation. Download the function code in <a href="https://gist.github.com/zimengyang/116e6e2d8cac298ac9df7a6acd913cb0">twitter.py</a> file. After base image and image are both ready, create the function twitter by:</p><pre>$ dispatch create function twitter --image python3-twitter ./twitter.py --secret twitter --secret aws</pre><p>Function twitter will consume aws secret for downloading image from s3 and twitter secret for tweeting.</p><h3>Create Subscription</h3><p>Now we have event driver and function ready, the last missing piece is that we need to create a subscription in Dispatch to make a bridge between incoming events and function invocation:</p><pre>$ dispatch create subscription twitter --event-type=&quot;aws.s3&quot;</pre><p>Here, we specify the target function twitter which we just created, also make sure the event-type is aws.s3. After doing this, the last missing piece is done.</p><h3>Let’s Upload Images</h3><p>Finally, we finish the workflow. Let’s upload some image to test it.</p><p>Go to the s3 bucket we just created, upload some pictures and wait them to be tweeted to your Twitter!</p><p>Also remember, if you specified <strong>prefix </strong>in CloudTrail, make sure your upload matches that prefix, either it is a folder prefix or file name prefix.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1ec9066701cd" width="1" height="1" alt=""><hr><p><a href="https://medium.com/dispatchframework/tweeting-images-by-dispatch-with-aws-cloud-events-1ec9066701cd">Tweeting Images by Dispatch with AWS Cloud Events</a> was originally published in <a href="https://medium.com/dispatchframework">dispatchframework</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Spring Support for Dispatch]]></title>
            <link>https://medium.com/dispatchframework/spring-support-for-dispatch-95c470c53475?source=rss----ee978f2747ea---4</link>
            <guid isPermaLink="false">https://medium.com/p/95c470c53475</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[spring]]></category>
            <category><![CDATA[vmware]]></category>
            <category><![CDATA[dispatches]]></category>
            <dc:creator><![CDATA[Nicholas Tenczar]]></dc:creator>
            <pubDate>Fri, 11 May 2018 20:52:39 GMT</pubDate>
            <atom:updated>2018-05-11T20:52:38.621Z</atom:updated>
            <content:encoded><![CDATA[<p>Several weeks ago Dispatch released support for creating Java functions through a new Java base image. If you are interested in Dispatch support for your favorite language see Ivan’s blog on <a href="https://medium.com/dispatchframework/adding-a-language-to-dispatch-3515cce08e9f">adding a language to Dispatch</a>. In this blog we are going to stick with Java and discuss how we support one of Java’s most popular frameworks, Spring. From its early days as a simple Java/J2EE application framework to the Java developer’s Swiss Army knife, Spring has been used to build lightly coupled, highly cohesive applications. Today we will see how to build these applications in Dispatch.</p><p>At its core Spring is a dependency injection / inversion of control container. It manages the lifecycles of the important beans in your application. This includes bean creation and wiring of disparate dependent beans. In a serverless world these facilities are less relevant due to the high level of specificity in serverless functions. A given Dispatch function is unlikely to include more than a dozen beans, which seems hardly worth the overhead of initializing the Spring application context. But Spring can do more than just manage beans; it provides support for aspect oriented programming.</p><p>Our simple application will use aspect oriented programming (AOP) to log invocations of our function and track execution time. Developers could use this audit data to isolate bottlenecks, provision more hardware, or improve the efficiency of their function. For this example we won’t focus on the business logic of the function rather we’ll concern ourselves with logging the execution time of the business logic. The following is the definition of a trivial AspectJ aspect that advises any method annotated with the custom annotation @Loggable</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ffacf19778992eb19fde4202f895385f/href">https://medium.com/media/ffacf19778992eb19fde4202f895385f/href</a></iframe><p>Whenever an @Loggable method is called, this advice will time the execution of the method and then post it to an external service. For this example, I’m posting to a sample REST API, but this could be any auditing/logging service you want. Also notice the use of Spring’s RestTemplate. This class provides for transparent serialization/deserialization of domain objects with zero configuration required by the end user. We will come back to the definition of RestTemplate later.</p><p>Now that we have our logging aspect we need the business logic that it will advise. In this case we are going to use a factorial calculator for its simplicity. Here is the definition of our calculator, notice the use of the @Loggable annotation.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/18e07aafedc7da40e59de8eae81a753b/href">https://medium.com/media/18e07aafedc7da40e59de8eae81a753b/href</a></iframe><p>Finally we need to define the function that Dispatch will execute in response to events or function invocation requests.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f9e442b85fc01bd4270693eaac9aef3b/href">https://medium.com/media/f9e442b85fc01bd4270693eaac9aef3b/href</a></iframe><p>Here our FunctionHandler accepts the FactorialCalculator in its constructor and then calls the calculate method in its own apply method. The Result class acts as a wrapper for the result, but it could be replaced BigInteger just as easily.</p><p>With these pieces in place we just need to initialize all of these beens in our Spring context and enable AspectJ auto proxying. Here is the full definition of the function class that we will place to Dispatch.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3426b994e8c5c6a7081f46bbe8b1d450/href">https://medium.com/media/3426b994e8c5c6a7081f46bbe8b1d450/href</a></iframe><p>How do you run this in Dispatch? I’m going to assume you have your own Dispatch instance running in a Kubernetes cluster. If you need help setting up a Dispatch install you can use our Getting Started doc found <a href="https://github.com/vmware/dispatch/blob/master/docs/_guides/quickstart.md">here</a>. With Dispatch installed and the cli configured on your machine you can use the following command to create the base image.</p><pre>dispatch create base-image java-base dispatchframework/java-base:0.0.3</pre><p>You can use dispatch get base-image to watch the progress of the base image provisioning. When the status shows as READY you can move on to creating the image.</p><pre>dispatch create image java-aop java-base --runtime-deps pom.xml</pre><p>In this case pom.xml is file containing the maven dependencies for our function.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9e38381cb7346821a9af443d4d01ef3d/href">https://medium.com/media/9e38381cb7346821a9af443d4d01ef3d/href</a></iframe><p>Finally let’s create the function using the HelloSpringAuditing.java file from earlier.</p><pre>dispatch create function java-aop audit-fn HelloSpringAuditing.java</pre><p>Again we can use dispatch get function to wait for the function to be ready. Once it is ready we can execute the function using:</p><pre>dispatch exec audit-fn --input &quot;50&quot; --wait --json</pre><p>If everything worked you should see output like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b23c80032deb101bf7981c3863f98672/href">https://medium.com/media/b23c80032deb101bf7981c3863f98672/href</a></iframe><p>This was a quick overview of using Spring in your Dispatch functions. If you are interested in how this support was added you can take a look at the java base image found <a href="https://github.com/dispatchframework/java-base-image">here</a>, and for more on Dispatch in general you can check out our website at <a href="http://dispatchframework.io/">dispatchframework.io</a>.</p><pre>{</pre><pre>&quot;blocking&quot;: true,</pre><pre>&quot;executedTime&quot;: 1525897389,</pre><pre>&quot;faasId&quot;: &quot;ed641f45-a575-49a1-898d-bbb1a57f9fa7&quot;,</pre><pre>&quot;finishedTime&quot;: 1525897391,</pre><pre>&quot;functionId&quot;: &quot;64defab7-e212-4837-9a91-4d639c0b7aa9&quot;,</pre><pre>&quot;functionName&quot;: &quot;log-fn&quot;,</pre><pre>&quot;input&quot;: 50,</pre><pre>&quot;logs&quot;: {</pre><pre>&quot;stderr&quot;: null,</pre><pre>&quot;stdout&quot;: [</pre><pre>&quot;Got response with id 101 and body: Method BigInteger io.dispatchframework.javabaseimage.HelloSpringAuditing$FactorialCalculator.calculate(int) executed in 30ms.&quot;</pre><pre>]</pre><pre>},</pre><pre>&quot;name&quot;: &quot;4463f1f3-7197-4247-8b76-603c4eb550bd&quot;,</pre><pre>&quot;output&quot;: {</pre><pre>&quot;computedFactorial&quot;: 3.0414093201713376e+64</pre><pre>},</pre><pre>&quot;reason&quot;: null,</pre><pre>&quot;secrets&quot;: [],</pre><pre>&quot;services&quot;: null,</pre><pre>&quot;status&quot;: &quot;READY&quot;,</pre><pre>&quot;tags&quot;: []</pre><pre>}</pre><p>This was a quick overview of using Spring in your Dispatch functions. If you are interested in how this support was added you can take a look at the java base image found <a href="https://github.com/dispatchframework/java-base-image">here</a>, and for more on Dispatch in general you can check out our website at <a href="http://dispatchframework.io/">dispatchframework.io</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=95c470c53475" width="1" height="1" alt=""><hr><p><a href="https://medium.com/dispatchframework/spring-support-for-dispatch-95c470c53475">Spring Support for Dispatch</a> was originally published in <a href="https://medium.com/dispatchframework">dispatchframework</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Adding a Language to Dispatch]]></title>
            <link>https://medium.com/dispatchframework/adding-a-language-to-dispatch-3515cce08e9f?source=rss----ee978f2747ea---4</link>
            <guid isPermaLink="false">https://medium.com/p/3515cce08e9f</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[clojure]]></category>
            <category><![CDATA[jvm]]></category>
            <dc:creator><![CDATA[Ivan Mikushin]]></dc:creator>
            <pubDate>Fri, 27 Apr 2018 18:59:03 GMT</pubDate>
            <atom:updated>2018-04-27T18:59:02.922Z</atom:updated>
            <content:encoded><![CDATA[<p>As of a couple weeks ago, you can run functions in <a href="https://vmware.github.io/dispatch/documentation/specs/language-support">ANY programming language</a> on Dispatch. To start, you need a <em>base image</em> for that language.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ThzkjOsGgkIW1hl2Z8sfdg.jpeg" /><figcaption>Build your FUNctions!</figcaption></figure><p>Dispatch already supports <a href="https://github.com/dispatchframework/nodejs-base-image">JavaScript</a>, <a href="https://github.com/dispatchframework/python3-base-image">Python 3</a>, <a href="https://github.com/dispatchframework/powershell-base-image">PowerShell</a>, <a href="https://github.com/dispatchframework/java-base-image">Java</a> and probably (by the time you’re reading this) others. I’m a big fan of <a href="https://clojure.org/">Clojure</a>, so I’ve created a <a href="https://github.com/dispatchframework/clojure-base-image">base image for it</a> to use as an example.</p><h3>Functions, Images, Base Images</h3><p>In Dispatch, <em>functions</em> are built on top of <em>images</em>, which themselves are built on top of <em>base images</em>. All of those are Docker images:</p><ul><li><em>Base image</em> provides the language runtime,</li><li><em>Image</em> provides library dependencies,</li><li><em>Function</em> wraps the function (source code) into a runtime API server, ready to execute incoming invocation requests</li></ul><p>We are building the <em>base image</em> for Clojure, which will contain templates for building images and functions. An overview of this process:</p><ol><li>Start with an empty Dockerfile</li><li>Choose the “FROM” image</li><li>Add language runtime and necessary system packages</li><li>Create image template</li><li>Create function template</li><li>Implement <a href="https://vmware.github.io/dispatch/documentation/specs/language-support#function-runtime-api">Function Runtime API</a></li><li>Write README</li></ol><h3>Choose the “FROM” image</h3><p>First, we need to choose the starting point, the “FROM” image. There are many great choices here (scratch, ubuntu, alpine, busybox, debian, vmware/photon2, etc.) depending on what your preferences for libc, package manager, package stability, image size, license and what not. Dispatch uses <a href="https://vmware.github.io/photon/">Photon OS</a> everywhere else, so we’ll use it here as well:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4036bf3f0388803c5d030b8a4f60246c/href">https://medium.com/media/4036bf3f0388803c5d030b8a4f60246c/href</a></iframe><h3>Add language runtime</h3><p>Usually you can install it with your package manager, e.g. for Node.js on vmware/photon2 that would look like this:</p><pre>tdnf install -y nodejs-8.3.0-1.ph2</pre><p>Our case is a bit different, because Clojure is a JVM language and I’d like to use the <a href="https://blog.docker.com/2018/04/improved-docker-container-integration-with-java-10/">container friendly Java 10</a> runtime, which Photon OS doesn’t provide. Also, turns out, vanilla <a href="http://jdk.java.net/10/">JDK 10</a> doesn’t want to “Just Work” on Photon OS, so we use <a href="https://www.azul.com/downloads/zulu/zulu-linux/">Zulu</a> (an excellent drop-in replacement):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/43fd367da62e421d818749262536a9ac/href">https://medium.com/media/43fd367da62e421d818749262536a9ac/href</a></iframe><p>Now we’ll fetch and install Leiningen and Clojure. <a href="https://leiningen.org/">Leiningen</a> (or lein) is a popular Clojure build and package manager based on <a href="http://maven.apache.org/">Maven</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e7642eead085048b0068669c1206d768/href">https://medium.com/media/e7642eead085048b0068669c1206d768/href</a></iframe><p>Now we have a solid Clojure runtime environment complete with package management tools in our base image.</p><h3>Create image template</h3><p>A Dispatch <em>base image</em> is supposed to have a directory to build <em>images</em> from. This directory should be specified in the <em>base image</em> metadata label <strong>io.dispatchframework.imageTemplate</strong> (the default value is /image-template):</p><pre>LABEL <strong>io.dispatchframework.imageTemplate</strong>=/image-template</pre><p>Typically, this directory only contains a Dockerfile:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/edd079a2d78865d8ee6193e308bbece5/href">https://medium.com/media/edd079a2d78865d8ee6193e308bbece5/href</a></iframe><p>This Dockerfile accepts 3 build arguments:</p><ul><li><strong>BASE_IMAGE</strong> — the <em>base image</em>, to build the <em>image</em> on top of</li><li><strong>SYSTEM_PACKAGES_FILE</strong> — lists required system packages in plain text format</li><li><strong>PACKAGES_FILE</strong> — library dependency manifest</li></ul><p>In the above Dockerfile, we read system packages from the file specified with SYSTEM_PACKAGES_FILE, make sure the list is not empty and has unique entries, and then install them with tdnf (Tiny DNF), the PhotonOS package manager.</p><p>Clojure uses <a href="https://clojure.org/reference/deps_and_cli">deps.edn</a> as its library manifest, so we just copy the provided file as deps.edn, and run clojure -Stree which fetches all the deps and lists them as a tree.</p><h3>Create function template</h3><p>A Dispatch <em>image</em> is supposed to have a directory to build <em>functions</em> from. This directory should be specified in the <em>image</em> metadata label <strong>io.dispatchframework.functionTemplate</strong> (the default value is /function-template):</p><pre>LABEL <strong>io.dispatchframework.functionTemplate</strong>=/function-template</pre><p>Since <em>images</em> are built on top of <em>base images</em>, we’re going to place that directory in our <em>base image</em>, and it will propagate to all derived images.</p><p>Typically, this directory only contains a Dockerfile:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bdd370a177c7c5e643bcf86f5c03dc04/href">https://medium.com/media/bdd370a177c7c5e643bcf86f5c03dc04/href</a></iframe><p>This Dockerfile accepts 2 build arguments:</p><ul><li><strong>IMAGE</strong> — <em>image</em>, to build <em>functions</em> on top of</li><li><strong>FUNCTION_SRC</strong> — function source code is copied into this file at build time</li></ul><p>We need to obtain the function and wrap it into the function server — an implementation of Function Runtime API.</p><p>We can run Clojure source files like scripts using clojure CLI tool. We add a couple lines to:</p><ol><li>Require our func-server.main namespace (the Function Runtime API implementation),</li><li>Grab the user-supplied function as <strong>function</strong> (by convention) and pass it as an argument to run our API server.</li></ol><h3>Implement Function Runtime API</h3><p>The <a href="https://vmware.github.io/dispatch/documentation/specs/language-support#function-runtime-api">Function Runtime API</a> server needs to wrap the user-supplied function and provide these endpoints:</p><pre>GET /healthz  - healthcheck<br>POST /*       - run function</pre><p>You can check out implementations for more languages on GitHub: <a href="https://github.com/dispatchframework">https://github.com/dispatchframework</a></p><p>Below is what needs to be done to implement it.</p><h4>Obtain the function from source code</h4><p>A function source code generally has enough information to fully define the function. For example, in JavaScript the function is assigned to module.exports — that’s all.</p><p>In Clojure it’s only slightly harder than in JavaScript. We just need a convention as to what function should be used as the entry point. This convention is up to the <em>base image</em>’s author, and needs to be clearly documented (the <em>base image</em>’s README is a good place).</p><p>In our case, as mentioned above, we will use a function named <strong>function</strong>, for example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/28f23ba01815dc92aeba8bc6b4a6396c/href">https://medium.com/media/28f23ba01815dc92aeba8bc6b4a6396c/href</a></iframe><p>Once we have the function, we <a href="https://github.com/dispatchframework/clojure-base-image/blob/master/func-server/src/func_server/routes.clj">construct a web app</a> from it and <a href="https://github.com/dispatchframework/clojure-base-image/blob/master/func-server/src/func_server/main.clj">launch it with an HTTP server</a>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a1c811138aca60323b2a5bf142dbe3f4/href">https://medium.com/media/a1c811138aca60323b2a5bf142dbe3f4/href</a></iframe><h4>Implement the API endpoints</h4><p><a href="https://github.com/dispatchframework/clojure-base-image/blob/master/func-server/src/func_server/routes.clj">Implementing this simple API</a> in Clojure is straightforward: for each endpoint you need to provide functions mapping requests to responses. See (handle f) below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/27741abed61bc4e8db4943907c2d77b3/href">https://medium.com/media/27741abed61bc4e8db4943907c2d77b3/href</a></iframe><p>Constructing the web app from a function — that’s what (app f) does — is basically taking the function and threading it through some transformations: API handling, JSON request parsing and response encoding.</p><h4>Capture any thrown error and writes to stdout/stderr</h4><p>In the above web app, (core/wrap-func f) does all the important work — capturing error and logs:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7397120f67cf001c811f71063ac03ee4/href">https://medium.com/media/7397120f67cf001c811f71063ac03ee4/href</a></iframe><p>Again, threading of a function through some higher order functions. <a href="https://github.com/dispatchframework/clojure-base-image/blob/master/func-server/src/func_server/core.clj">Here’s the full source</a> — for the brave and true!</p><h3>Write README</h3><p>You definitely want your users to know how to get started with your new language pack. So, make sure to write up quick instructions in the <a href="https://github.com/dispatchframework/clojure-base-image/blob/master/README.md">README</a>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3515cce08e9f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/dispatchframework/adding-a-language-to-dispatch-3515cce08e9f">Adding a Language to Dispatch</a> was originally published in <a href="https://medium.com/dispatchframework">dispatchframework</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Dispatch + Services]]></title>
            <link>https://medium.com/dispatchframework/dispatch-services-a501e69613eb?source=rss----ee978f2747ea---4</link>
            <guid isPermaLink="false">https://medium.com/p/a501e69613eb</guid>
            <category><![CDATA[vmware]]></category>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[dispatches]]></category>
            <category><![CDATA[functions-as-a-service]]></category>
            <category><![CDATA[serverless]]></category>
            <dc:creator><![CDATA[Berndt Jung]]></dc:creator>
            <pubDate>Wed, 11 Apr 2018 21:22:18 GMT</pubDate>
            <atom:updated>2018-04-11T22:16:30.334Z</atom:updated>
            <content:encoded><![CDATA[<p>Functions are stateless. Applications are not. Functions as a Service (FaaS) depend on external services to provide state and other services in order to build more interesting applications. This blog post highlights the new service management functionality within <a href="https://vmware.github.io/dispatch/">Dispatch</a>. This feature is still experimental. Additionally, we will be demonstrating this feature a the <a href="https://cfna18.sched.com/event/f8ee85557deea94f671bfdf756b8f743">Cloud Foundry Summit</a> later this month.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*-dRzUWQnlqgoLSo8rObdBw.png" /></figure><p>In order to bring services to Dispatch, we are leveraging the <a href="https://www.openservicebrokerapi.org/">Open Services Broker API</a> (OSBAPI). This API defines a contract for listing, provisioning and binding services such as databases. By working against this specification, we can easily integrate with any service which has an open service broker implementation. This includes just about any service designed to work with Cloud Foundry, which immediately gives us a great service catalog.</p><p>This post will be a demonstration of using the new services support in Dispatch. More specifically, we will be provisioning and binding an Azure Postgres database from Dispatch, then making that binding available to Dispatch functions. Now your serverless applications have state!</p><p>As stated earlier, this support is still experimental, so it’s likely that the CLI options as well as installation steps will change.</p><h3>Prerequisites</h3><ol><li>A working kubernetes environment with helm initialized.</li><li>Dispatch CLI (<a href="https://github.com/vmware/dispatch/releases">v.0.1.11 release</a>)</li><li>An Azure account</li></ol><p>For this demo, we are installing Dispatch locally via minikube.</p><h3>Installing</h3><h4>Install Dispatch</h4><p>Install Dispatch and create some base resources. See the <a href="https://vmware.github.io/dispatch/documentation/guides/quickstart">quickstart</a> for more information about configuring and installing Dispatch on Kubernetes.</p><pre>$ dispatch install -f config.yaml<br>...<br>Config file written to: /Users/bjung/.dispatch/config.json<br>$ cd examples/<br>$ dispatch create -f seed.yaml <br>Created BaseImage: nodejs6-base<br>Created BaseImage: python3-base<br>Created BaseImage: powershell-base<br>Created Image: nodejs6<br>Created Image: python3<br>Created Image: powershell<br>Created Function: hello-py<br>Created Function: http-py<br>Created Function: hello-js<br>Created Function: hello-ps1<br>Created Secret: open-sesame</pre><h4>Install the service catalog</h4><p>Dispatch is leveraging the Kubernetes service catalog as a proxy to open service brokers. Installing the service catalog and service brokers is currently a manual step handled outside of Dispatch. This is all likely to change as the service management evolves.</p><pre># Add the svc-cat helm repository<br>$ helm repo add svc-cat \<br>    <a href="https://svc-catalog-charts.storage.googleapis.com/">https://svc-catalog-charts.storage.googleapis.com</a><br>&quot;svc-cat&quot; has been added to your repositories<br>$ helm install svc-cat/catalog \<br>    --name catalog --namespace dispatch --wait</pre><h4>Install the Azure Service Broker</h4><p>You will need an Azure account as well as some <a href="https://github.com/Azure/open-service-broker-azure/blob/master/docs/quickstart-minikube.md#cluster-setup">setup</a>.</p><pre># Add the azure helm <br>$ helm repo add azure \<br>    <a href="https://kubernetescharts.blob.core.windows.net/azure">https://kubernetescharts.blob.core.windows.net/azure</a><br>&quot;azure&quot; has been added to your repositories<br>$ helm install azure/open-service-broker-azure --name osba --namespace dispatch --wait \<br>  --set azure.subscriptionId=$AZURE_SUBSCRIPTION_ID \<br>  --set azure.tenantId=$AZURE_TENANT_ID \<br>  --set azure.clientId=$AZURE_CLIENT_ID \<br>  --set azure.clientSecret=$AZURE_CLIENT_SECRET</pre><p>Be aware, it can take a while for the pods to become ready.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z-qwKhgV_bMprpOAQRX4Rw.png" /><figcaption>All pods up and running</figcaption></figure><h3>Working with Services</h3><p>At this point, your environment should be ready to go. It takes a little while for dispatch to sync with the service catalog, so be patient. Also, don’t be alarmed if you see more or less services and plans. The Azure service broker is under heavy development.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p8uSOYag3CfcQUAW05fZGQ.png" /><figcaption>Listing available service classes</figcaption></figure><p>In this example we are going to provision and bind a Postgres database which we can use from a function. The real trick is understanding what parameters are required to properly create a service instance. In the case of the azure services, the <a href="https://github.com/Azure/open-service-broker-azure/blob/master/docs/modules/postgresql.md">documentation</a> is your friend. The OSBAPI includes optional schemas for provisioning and binding, but the Azure service broker does not include these fields.</p><h4>Create a Postgres service instance</h4><pre>$ dispatch create serviceinstance azure-pg azure-postgresql \<br>    basic50 --params &#39;<br>{<br>    &quot;location&quot;: &quot;westus&quot;,<br>    &quot;resourceGroup&quot;: &quot;demo&quot;,<br>    &quot;firewallRules&quot;: [<br>        {<br>            &quot;startIPAddress&quot;: &quot;0.0.0.0&quot;,<br>            &quot;endIPAddress&quot;: &quot;255.255.255.255&quot;,<br>            &quot;name&quot;: &quot;AllowAll&quot;<br>        }<br>    ]<br>}&#39;<br>Created serviceinstance: azure-pg</pre><p>What the above Dispatch command will do is provision and bind a Postgres database via the OSBAPI. What does this mean? Provisioning means creating a new “Azure Database for PostgreSQL server” as well as creating a new database on the server. There are also ways of re-using existing servers and even existing databases, but that’s outside our scope right now. Binding means creating credentials (username/password) for the database and storing those credentials securely. Now, these credentials can be injected into the function similarly to how secrets are injected.</p><p>Provisioning takes some time ~10 minutes. When completed you should see the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*roNfOcl10gbkgldqaNNVfw.png" /><figcaption>A provisioned and bound postgres database</figcaption></figure><p>We can easily verify exactly what happened. If you log into your Azure console and navigate to the “demo” resource group, you will see an “Azure Database for PostgreSQL server” resource with a UUID for a name. Within Dispatch, this UUID corresponds to both the azure-pg serviceinstance’s ID, and the name of the Dispatch secret which stores the binding information.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vxbkuMs3TKGxbfqvV6g_dQ.png" /><figcaption>The secret which stores the binding data</figcaption></figure><h4>Using the service from within a function</h4><p>Of course the whole point of all this is to be able to use services from within functions. We have now deployed a Postgres server, created a database and credentials. Those credentials (binding) are stored as Dispatch secrets and can be made available to functions with a simple flag. First, let’s create an image which contains the Postgres driver dependency:</p><pre>$ cd examples/python3/postgres<br>dispatch create image python3-pg python3-base \<br>    --runtime-deps requirements.txt<br>Created image: python3-pg</pre><p>Then create the function:</p><pre>$ dispatch create function python3-pg pg-example postgres.py \<br>    --service azure-pg --schema-in postgres.schema.json<br>Created function: pg-example</pre><p>By adding the --service azure-pg flag we are telling Dispatch to inject the binding to the function at execution time. Credentials are not hard-coded anywhere.</p><p>The function we created is a very simple function which just creates a table (if it doesn’t exist) and writes a simple row from input. We do input validation via the schema defined with the --schema-in postgres.schema.json flag.</p><p>Finally, executing the function:</p><pre>$ dispatch exec pg-example --wait \<br>    --input &#39;{&quot;num&quot;: 1, &quot;data&quot;: &quot;hello everyone&quot;}&#39;<br>{<br>    &quot;blocking&quot;: true,<br>    &quot;executedTime&quot;: 1523469967,<br>    &quot;faasId&quot;: &quot;e130c396-e6af-49f5-983a-e343299bd170&quot;,<br>    &quot;finishedTime&quot;: 1523469970,<br>    &quot;functionId&quot;: &quot;281c05bb-2400-4573-b4d6-e39886b58b7a&quot;,<br>    &quot;functionName&quot;: &quot;pg-example&quot;,<br>    &quot;input&quot;: {<br>        &quot;data&quot;: &quot;hello everyone&quot;,<br>        &quot;num&quot;: 1<br>    },<br>    &quot;logs&quot;: [<br>        &quot;num: 1, data: hello everyone&quot;<br>    ],<br>    &quot;name&quot;: &quot;9d8ee54d-a17b-4251-b661-d6ad1daac88b&quot;,<br>    &quot;output&quot;: [<br>        {<br>            &quot;data&quot;: &quot;hello everyone&quot;,<br>            &quot;num&quot;: 1<br>        }<br>    ],<br>    &quot;reason&quot;: null,<br>    &quot;secrets&quot;: [],<br>    &quot;services&quot;: null,<br>    &quot;status&quot;: &quot;READY&quot;,<br>    &quot;tags&quot;: []<br>}</pre><p>We can see based on the output field that the data has been written to the database. If we run the same function again (with different input), we can see the function can retrieve the previous data:</p><pre>$ dispatch exec pg-example --wait \<br>    --input &#39;{&quot;num&quot;: 2, &quot;data&quot;: &quot;hello everyone again&quot;}&#39;<br>{<br>    &quot;blocking&quot;: true,<br>    &quot;executedTime&quot;: 1523470034,<br>    &quot;faasId&quot;: &quot;e130c396-e6af-49f5-983a-e343299bd170&quot;,<br>    &quot;finishedTime&quot;: 1523470034,<br>    &quot;functionId&quot;: &quot;281c05bb-2400-4573-b4d6-e39886b58b7a&quot;,<br>    &quot;functionName&quot;: &quot;pg-example&quot;,<br>    &quot;input&quot;: {<br>        &quot;data&quot;: &quot;hello everyone again&quot;,<br>        &quot;num&quot;: 2<br>    },<br>    &quot;logs&quot;: [<br>        &quot;num: 1, data: hello everyone&quot;,<br>        &quot;num: 2, data: hello everyone again&quot;<br>    ],<br>    &quot;name&quot;: &quot;0ef780e8-8451-4146-a306-a1cc0ed621eb&quot;,<br>    &quot;output&quot;: [<br>        {<br>            &quot;data&quot;: &quot;hello everyone&quot;,<br>            &quot;num&quot;: 1<br>        },<br>        {<br>            &quot;data&quot;: &quot;hello everyone again&quot;,<br>            &quot;num&quot;: 2<br>        }<br>    ],<br>    &quot;reason&quot;: null,<br>    &quot;secrets&quot;: [],<br>    &quot;services&quot;: null,<br>    &quot;status&quot;: &quot;READY&quot;,<br>    &quot;tags&quot;: []<br>}</pre><h4>Exposing an API endpoint</h4><p>Now we can take our function and expose an HTTP API endpoint:</p><pre>$ dispatch create api post-pg-example pg-example \<br>    --auth public --https-only --method POST --path /postgres/demo<br>Created api: post-pg-example</pre><p>Use the Dispatch config to determine the host and HTTPS port:</p><pre>$ cat ~/.dispatch/config.json<br>{<br>    &quot;host&quot;: &quot;192.168.64.55&quot;,<br>    &quot;port&quot;: 32312,<br>    &quot;scheme&quot;: &quot;https&quot;,<br>    &quot;organization&quot;: &quot;dispatch&quot;,<br>    &quot;cookie&quot;: &quot;******&quot;,<br>    &quot;insecure&quot;: true,<br>    &quot;api-https-port&quot;: 32191,<br>    &quot;api-http-port&quot;: 32023<br>}</pre><p>And it’s live!</p><pre>$ curl -k <a href="https://192.168.64.55:32191/postgres/demo">https://192.168.64.55:32191/postgres/demo</a> \<br>    -H &#39;Content-type: application/json&#39; \<br>    -d &#39;{&quot;num&quot;: 3, &quot;data&quot;: &quot;hello from API&quot;}&#39;<br>[<br>    {&quot;data&quot;:&quot;hello everyone&quot;,&quot;num&quot;:1},<br>    {&quot;data&quot;:&quot;hello everyone again&quot;,&quot;num&quot;:2},<br>    {&quot;data&quot;:&quot;hello from API&quot;,&quot;num&quot;:3}<br>]</pre><h4>Beyond Azure</h4><p>This post demonstrated bringing Azure services to Dispatch, but because the services integration is based on the OSBAPI, any compatible service can be used. Azure was chosen because it offers a compelling list of services and comes with Kubernetes service catalog binding. In other words, it’s an easy integration. As we evolve this feature, we will make adding any OSBAPI compatible service easy directly via Dispatch.</p><h3>Conclusion</h3><p>The above is a very basic example of how you can now leverage external services which advertise via the OSBAPI. With Dispatch you now have the tools to link functions with stateful services like databases and present them via APIs. This is the basis of most web-services. The services support presented, is still very experimental, but we will continue to develop and refine.</p><p>If you are going to the <a href="https://cfna18.sched.com/event/f8ee85557deea94f671bfdf756b8f743">Cloud Foundry Summit North America 2018</a>, please come hear us talk about this feature in person.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a501e69613eb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/dispatchframework/dispatch-services-a501e69613eb">Dispatch + Services</a> was originally published in <a href="https://medium.com/dispatchframework">dispatchframework</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>