<?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[Stories by Evan Wong on Medium]]></title>
        <description><![CDATA[Stories by Evan Wong on Medium]]></description>
        <link>https://medium.com/@evan-wong?source=rss-2645220b89c6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*1FivjyB1jCpS9dulnFyOSg.png</url>
            <title>Stories by Evan Wong on Medium</title>
            <link>https://medium.com/@evan-wong?source=rss-2645220b89c6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 00:49:56 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@evan-wong/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to 3M (Manage, Monitor and Monetize) API using Azure API Management]]></title>
            <link>https://evan-wong.medium.com/how-to-3m-manage-monitor-and-monetize-api-using-azure-api-management-99c865e43ad8?source=rss-2645220b89c6------2</link>
            <guid isPermaLink="false">https://medium.com/p/99c865e43ad8</guid>
            <dc:creator><![CDATA[Evan Wong]]></dc:creator>
            <pubDate>Thu, 03 Dec 2020 06:47:03 GMT</pubDate>
            <atom:updated>2020-12-03T06:48:53.949Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to 3M (Manage, Monitor and Monetize) APIs using Azure API Management</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wn6O9dl1rVvguZP9iCWrLQ.png" /><figcaption>Azure API Management Services Architecture</figcaption></figure><p>In my previous <a href="https://evan-wong.medium.com/create-api-using-azure-function-with-python-and-azure-cosmos-db-afda09338d82">article</a>, I have talked about the steps by steps on how to build APIs from scratch using Visual Studio Code with Python, Azure Functions and Cosmos DB.</p><p>In this article, I’d like to share on how to use the Azure API Management to help you to manage, monitor, secure and monetize those APIs that we have created earlier.</p><h3>What is API Management</h3><p>API Management is a process to help you to manage the APIs that are typically act as the functions or logics for a certain specific use cases. For example, a bank that a backend service that used to create new customer data, a service that inquire interest rate, and a service that check a customer’s credit worthiness.</p><p>These backend services are usually used by the internal systems, in certain scenario, where we would need to expose these services to external, this is where we would need to make sure the APIs are securely managed and governed. Hence, API Management provides the capabilities to help you to secure the API-protect the API by only allowing certain users to access and publish only the necessary APIs to external party to consume. Other than this, API Management also provide the capabilities to monitor the APIs-analysis the trend, consumption, able to monetize the APIs by setting up pricing rules, etc. API Management usually would provide a portal to allow developers to call, test the APIs on the sandbox provided.</p><p>An API Management solution typically consist of the following components — API Gateway, API Authoring/Publishing tool, Reporting &amp; Analytics, Developer Portal and Monetization.</p><h4>API Gateway</h4><p>The function of the API Gateway within the API Management solution is a server that acts as an API front-end, receives API requests, enforces throttling and security policies, passes requests to the back-end service and then passes the response back to the requester.</p><h4>API Publishing Tool</h4><p>A tool to create/define APIs by scratch or using the <a href="https://en.wikipedia.org/wiki/OpenAPI_Specification">OpenAPI</a>, WADL, WSDL specifications, generate API documentation, govern API usage through access and usage policies for APIs, test and debug the execution of API, including security testing.</p><h4>Developer Portal</h4><p>A portal provides to the developers in a single convenient source information and functionality including documentation, tutorials, sample code, software development kits, an interactive API console and sandbox to trial APIs.</p><h4>Reporting &amp; Analytics</h4><p>Monitor API usage and load such as API calls, completed transactions, number of data objects returned, amount of compute time and other internal resources consumed, volume of data transferred.</p><h4>Monetization</h4><p>API Management also provide the functionality to support charging for access to commercial APIs. This functionality can include support for setting up pricing rules, based on usage, load and functionality.</p><h3>Azure API Management Services</h3><p><a href="https://azure.microsoft.com/en-us/services/api-management">Azure API Management Services</a> is a hybrid API Management platform that can manage APIs across different Clouds and on-premises. One of the advantage of using Azure API Management is that one can quickly transform existing available services that are created using Azure services such as Azure Functions, App Services into REST API.</p><p>In exercise, we would be extending the APIs that were created in the earlier articles.</p><h3>Outline</h3><p>In this tutorial, we would be doing the following steps:</p><ol><li>Create a new API Management Services on the Azure portal.</li><li>Define APIs</li><li>Create policies</li><li>Monitor the APIs</li></ol><h3>Prerequisites</h3><ol><li>Azure account with a valid subscription —<a href="https://portal.azure.com/"> https://portal.azure.com</a></li><li>Source codes — <a href="https://github.com/echoesian/azure-function">https://github.com/echoesian/azure-function</a></li></ol><h3>Create a New API Management Service</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Wm3AKhV2mo94HnI1odOTpQ.png" /></figure><p>After login into the Azure portal, get to the API Management services by typing on the search bar on the top.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0zurhc0FdTi8KEkQ3FoSmw.png" /></figure><p>On the API Management services page, click on the Add button. This brings you to the Create API Management page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C_y1ULOXFLUX6VEhYrJcxA.png" /></figure><p>Choose the subscription and the resource group that you want the resource to reside in. Create a new resource group if necessary.</p><p>Choose the region of your choice, enter a resource name, organization name and the administrator email.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_D6Kmzh07GsNeymICgdg8A.png" /><figcaption>API Management Service Pricing Tier</figcaption></figure><p>On the pricing tier section, there are several options to choose from. The Developer pricing tier provides the cheapest cost or free depends on the usage but there is no SLA, so it is not recommended to use for Production.</p><p>Click Review + create button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EvgX6W4tb-ulrhsphyakIQ.png" /></figure><p>If validation is passed, click on the Create button to provision the new API Management service instance.</p><h3>Define APIs</h3><p>After the new API Management service instance has been created. You can navigate to the APIs section to define APIs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bMgRw0Q9jiRw0qsKNyUr5Q.png" /></figure><p>On the APIs section, there are several ways for us to add APIs. This includes creation using OpenAPI, WADL, WSDL, or using existing Logic App, App Service, Function App or even create the API from scratch using the Blank API option. In this example, we would be using the Function App option to create the API using existing REST APIs that were created earlier on Function App.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*okJQGFtePtrvBn27QMMnGw.png" /></figure><p>On the Create from Function App dialog, choose the existing Function App by clicking on the browse button. This will bring you to the Import Azure Functions page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8FKhmhiF5wJA3xpwoPKfEA.png" /></figure><p>On the Import Azure Functions page, click on the <em>Configure required settings </em>button, choose the function app name that was created in the previous blog. For example, in my case, the Function App name is “serverless-python”, once it is selected, you should see all the available functions to choose from.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Tggx1Rv3PHwtn-no7ZAujA.png" /><figcaption>Azure functions</figcaption></figure><p>These functions should be included “CreateUser” and “GetUsers”. Select both of them and click Select.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s51lJmK4LEB82LpPwiukNQ.png" /></figure><p>Back to the dialog, you can enter the display name and name of the API or leave it as default. Click Create. Notice that the Base URL is automatically assigned to you using Azure default API DNS name.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eQ-UmfyNWa2S_H46l_xobw.png" /></figure><p>Delete the CreateUser API (POST method) and GetUsers (POST method) as we are only interested in defining the API for CreateUser on GET and GetUsers on GET.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/801/1*RWZQnadycXq1WR2ZiH2P0w.png" /></figure><p>Both of the APIs should look like the above now.</p><p>Next, we will need to configure both APIs. Let’s start configure the first one, CreateUser.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/801/1*RWZQnadycXq1WR2ZiH2P0w.png" /></figure><p>Click on the Definitions tab.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jbPcQAr2SmeZu8_MBEddKA.png" /></figure><p>On the operations tab, on the Frontend section, click on the pencil icon to open the form-based editor.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UGCNsmj9FnBrkElDn89DjA.png" /></figure><p>On this page, you can change the display name and URL. Notice the URL is the path to call the API eventually. Leave it as default. Scroll to the bottom of the page to reach to the Query configuration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3NUr97YC4vrfZvhB7qV-vA.png" /></figure><p>Add a parameter to the Query parameters. Key in “name” as the Name parameter and any name for the Values parameter. Click Save. To test the API, on the top bar, click on the Test tab.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FLAjn27EYQ45hLyuu0zUKg.png" /></figure><p>On the Test page, choose the value of the name from the dropdown list box. Click Send.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AJ7LHqEqVTNkBGCRYQd3HA.png" /></figure><p>If the call is successful, you should see the response back 200 OK.</p><h3>Throttling</h3><p>One of the most popular feature of an API Management solution is to be able to control the incoming traffic requests to the API Gateway.</p><p>API calls could be overwhelmed, so being able to throttle the incoming requests is a key capability on an API Management tool. This is important in order to protect the APIs from being abused or overused. In Azure API Management, you can use rate limits or quotas to control the API calls.</p><h4>Rate limits</h4><p>Rate limits are usually used to protect against short and intense volume bursts. For example, if you know your backend service has a bottleneck at its database with a high call volume, you could set a rate-limit-by-key policy to not allow high call volume by using this setting.</p><h4>Quotas</h4><p>Quotas are usually used for controlling call rates over a longer period of time. For example, they can set the total number of calls that a particular subscriber can make within a given month. For monetizing your API, quotas can also be set differently for tier-based subscriptions. For example, a Basic tier subscription might be able to make no more than 10,000 calls a month but a Premium tier could go up to 100,000,000 calls each month.</p><p>Within Azure API Management, rate limits are typically propagated faster across the nodes to protect against spikes. In contrast, usage quota information is used over a longer term and hence its implementation is different.</p><p>In this topic, we will be using rate limit to control the traffic. Rate limit can be used to control traffic based on IP address, user identity, client header but for this case, we will just use rate limit to blanket control the traffic.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qdtgqE42wnhSaqc2mRmZ8A.png" /></figure><p>Go to the APIs section, click on the API name, on the design section, click on the <em>GetUsers </em>operation. On the Inbound processing, click on the policy code editor.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R-wODCI9N6l1v_PSl-nrHA.png" /></figure><p>On the policy code editor, enter a new line after the set-backend-service and input the following:</p><p><em>&lt;rate-limit calls=”10&quot; renewal-period=”30&quot; /&gt;</em></p><p>This means, we want to limit the calls up to maximum of 10 during the time interval set on the “renewal-period” in seconds.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fgAlvWHPNIy5MOWQ7iPhBA.png" /></figure><p>To test this, let’s go to the Test section. Go down to the bottom of the screen and click Send for more than 10 times continuously. After the calls are more than 10 times, you should see there will be error response from the HTTP response —<strong> 429 Too Many Requests.</strong></p><h3>Monitoring</h3><p>Lastly, we would want to monitor and analysis the API management, for example, we can see how many requests have been performed in a particular duration, data transfer rates, response time, etc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w0KtT1hka9A5ed6NU6vGqA.png" /></figure><h3>Summary</h3><p>There are many others capabilities which we can do as well in Azure API Management such as publishing and designing the Developer portal, grouping the APIs into category/product, user identity and authentication, certificates, etc.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=99c865e43ad8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Active Directory Synchronization between Microsoft Azure and Amazon Web Services]]></title>
            <link>https://evan-wong.medium.com/active-directory-synchronization-between-microsoft-azure-and-amazon-web-services-1ecc672bfd40?source=rss-2645220b89c6------2</link>
            <guid isPermaLink="false">https://medium.com/p/1ecc672bfd40</guid>
            <dc:creator><![CDATA[Evan Wong]]></dc:creator>
            <pubDate>Tue, 24 Nov 2020 09:43:56 GMT</pubDate>
            <atom:updated>2020-11-24T10:39:08.008Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5Q9t54Ic49REsFUB_lbR8w.png" /><figcaption>Active Directory Synchronization to Azure AD from AWS</figcaption></figure><p>Running workloads on different Clouds together with on-premise locations are getting more and more common nowadays. Many organizations do not run 100% Cloud-Native applications for their businesses, they are still using traditional applications or legacy systems that typically do not work very well on the Cloud.</p><p>For instance, a bank that could have AS/400 loan origination systems running on-premise and at the same time they would have CRM applications running on the Cloud. Another example, a streaming services company that are using Windows Servers with IIS to power their web applications on the AWS for several years until recently they realize in order to avoid vendor lock-in, having workloads distributed across different Clouds could be a good idea.</p><p>In most cases where user identity management is concerned, organizations are most likely use certain identity management software to help them to control users, groups and roles and to secure access to their applications. Microsoft Active Directory is one of the most widely used identity management solution especially in the traditional on-premise or virtualization setup environment.</p><p>So, the question is, how do I be able to reuse my existing AD for my new applications that is planned to be deployed on another Cloud? The answer is using Azure Active Directory, Azure Active Directory Domain Services and Azure AD Connect.</p><p>In the diagram above, you can see both sides of the Cloud are installed with Microsoft Active Directory. On AWS, the EC2 could be installed with Microsoft Active Directory Domain Services as the local user identity management. Typically in Production environment, this service should be on a dedicated server with high availability setup to avoid single point of failure. This server would then installed with Azure AD Connect. It is used to synchronized the metadata to the Azure AD. On the Azure, Windows Server that are domain-joined would need a Azure Active Directory Domain Services (Azure AD DS) for authentication. This is a fully managed service that provides user authentication, for the domain-joined servers. But, we need a service to be able to add, modify and delete users, groups, this is where Azure AD comes in. The data from Azure AD would be synchronized to the Azure AD DS from time to time.</p><p>In this article, I want to share with you on how can I use my users created in AWS AD to login into the domain-joined servers in Azure.</p><h3>What is Azure Active Directory?</h3><p><a href="https://azure.microsoft.com/en-us/services/active-directory/">Azure Active Directory</a> or Azure AD is a Microsoft’s cloud-based identity and access management service, which helps users sign in and access resources in:</p><ul><li>External resources, such as Microsoft 365, the Azure portal, and thousands of other SaaS applications.</li><li>Internal resources, such as apps on the corporate network and intranet, along with any cloud apps developed by your own organization.</li></ul><p>It provides single sign-on and multi-factor authentication to help protect users from 99.9 percent of cybersecurity attacks.</p><h3>What is Azure Active Directory Domain Services?</h3><p><a href="https://azure.microsoft.com/en-us/services/active-directory-ds/">Azure Active Directory Domain Services</a> (AD DS) provides managed domain services such as domain join, group policy, lightweight directory access protocol (LDAP), and Kerberos / NTLM authentication. You use these domain services without the need to deploy, manage, and patch domain controllers (DCs) in the cloud.</p><h3>Hybrid Active Directory Use Cases</h3><h4>Use Case 1 : Leverage on existing users management on a separate Cloud or on-premise</h4><p>For this scenario, an organization probably have already invested a huge Active Directory infrastructure and wanted to leverage their existing AD for usage on Azure.</p><h4>Use Case 2: On-Premise Traditional Active Directory</h4><p>Some of the customers are still using their traditional Active Directory setup on-premise to run their day to day business. They could not afford to lose their effort on the current setup and do not see to modernize their infrastructure or applications anytime sooner. Therefore, with this hybrid AD approach, they would be able to lift and shift to the Azure quickly while leveraging on the existing on-premise setup users management capabilities especially on the schema extension and rely on trust relationships.</p><p>Having said that, there are some scenarios where we could get away on Azure AD DS and/or Azure AD. For situation where companies are only running on Cloud-Native applications that are usually using modern authentication services.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*dcTPU9uoir3rp94p.png" /><figcaption>Microsoft Active Directory Services Comparison, credit to <a href="https://www.ciraltos.com/active-directory-domain-service-azure-active-directory-and-azure-active-directory-domain-service-explained/">https://www.ciraltos.com/active-directory-domain-service-azure-active-directory-and-azure-active-directory-domain-service-explained/</a></figcaption></figure><h3>Prerequisites</h3><ol><li>An AWS account with a valid subscription</li><li>An Azure account with a valid subscription</li><li>Provision a AWS EC2 Windows Server 2019 (can use the free tier option t2.micro — 1vCPU, 1GB memory)</li><li>Provision a Azure VM</li><li>Domain names for both AWS and Azure (both sides much match). For e.g. The domain name on Azure is<em> evanad.onmicrosoft.com </em>then on the AWS AD must be <em>evanad.com</em>.</li><li><a href="https://www.microsoft.com/en-us/download/details.aspx?id=47594">AD Connect</a> tool or it can be downloaded within the server</li></ol><h3>Add Azure AD Custom Domain Name (Optional)</h3><p>If you are using Microsoft email or other public email providers, most likely the tenant would be assigned to the Microsoft owned domain — *.onmicrosoft.com. If this is the case, you would need to add in a custom domain name to the tenant.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/558/1*jOSZZfAYl31c3w6zr5NpEA.png" /></figure><p>Navigate to the Azure Active Directory page, scroll the the bottom on the left menu, click on the Custom domain names.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MrwM3p3i9Kk-SSL_kYW3XQ.png" /></figure><p>Click the + Add custom domain button and key in a custom domain name on the right panel. Click Add domain.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xuCkZy_880nJc__cnraLJA.png" /><figcaption>TXT record</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FvyKQSttep2Y3lYzTQ4pBQ.png" /><figcaption>MX record</figcaption></figure><p>Take note on the DNS settings which you would need to add in a record for the TXT and MX record type.</p><p>After that, create a DNS by navigating to the DNS zones.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KQR4xHqX_T5EKb-EK4F3kw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/757/1*sqTd_TVi3Rcz_Go--g6yDQ.png" /></figure><p>Click the the + Add button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DCqBVXC84wcXkG9tu8Jjvw.png" /></figure><p>Enter the name for the DNS and click Review + Create. After validation is passed, click Create.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/692/1*VJbDWCH30qH2duERoe2cyQ.png" /></figure><p>Once it is created, click on the + Record set.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*Zbcrw2nOW7d8gYOoqijKLg.png" /></figure><p>Enter @ for the name, TXT for the type and paste the value from the earlier exercise. Set the TTL to 3600.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/956/1*-_MNwIAguWyNHDfSuCMoBA.png" /></figure><p>Then, add in the MX record by entering all the details copied from the DNS servers earlier.</p><h3>Add Azure AD Domain Services</h3><p>To setup a Directory Service, we can provision a Windows Server and install the Active Directory Domain Services or we can use managed service on the Cloud such as <a href="https://azure.microsoft.com/en-us/services/active-directory-ds/">Azure AD Domain Services</a>. Using the managed AD Domain Services is very straight-forward, easy and very quick to setup. It manages the high availability to make sure that the Directory services are always available and to ensure optimum uptime.</p><p>To add an Azure AD Domain Services, on the Azure portal, type “Azure AD Domain Services” on the top search bar.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h_sQcl13xXctW6Pzu8dCBA.png" /></figure><p>Click on the Azure AD Domain Services.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ksflnGOnXfRh-2wh-whFkQ.png" /></figure><p>On the landing page, click the Create Azure AD Domain Services button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VlCUnrKgQfwr5mwyc7kfOw.png" /></figure><p>On the basic page, create a resource group of choose a existing resource group. Enter a valid domain name that is reachable. Leave others as default and navigate to the Networking section.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Sten7gIpe_GRvKrYsrRc-A.png" /></figure><p>Create a new Virtual network or choose an existing Virtual network, leave others as default and click Review + create.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lu080283pozBHbLMgmxeYQ.png" /></figure><p>On the summary page, review all the settings and click Create to setup the AD Domain Services.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RoTRFDLAGCqRL45stNZ6Kg.png" /></figure><p>There will be the pop-up confirmation to remind on the choices are final and it won’t be able to change afterwards, click OK.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vlWUtkEnMjOaGTpJTWRxGA.png" /></figure><p>Once the AD Domain Services is successfully deployed, navigate back to the service page. Click on the newly created AD Domain Services.</p><h4>Update DNS settings for the Azure virtual network</h4><p>With Azure AD DS successfully deployed, now configure the virtual network to allow other connected VMs and applications to use the managed domain. To provide this connectivity, update the DNS server settings for your virtual network to point to the two IP addresses where the managed domain is deployed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4AD40SYUCsqmQJJ8IWL9VA.png" /></figure><p>Go down to the section on “Update DNS server settings…” and click Configure.</p><h3>Create New Windows Server Virtual Machine</h3><p>On the main portal page, click on the Virtual Machines.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xBmpZWp5ccvzlMuH4i9MjA.png" /><figcaption>Azure portal</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zwtHpn-pRWVyD7ctwoMhIA.png" /></figure><p>On the Virtual machines page, click Add and choose Virtual machine.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cX_Eu0phpE4aSHy0Jj7KOw.png" /></figure><p>Create a new resource group or choose existing resource group. Enter a name for the virtual machine. Choose the preferred region, no infrastructure redundancy required, Windows Server 2019 Datacenter — Gen1 for the image and choose Standard_B1ms or any preferred size. Scroll to the bottom.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Dq2u_GuHODBfW1yMCUzORg.png" /></figure><p>Enter an username and password to access to the virtual machine later on. Leave others as default.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NJqbA4LPjrfHIKtXHDHLhA.png" /></figure><p>This is an important step, navigate to the Networking tab, choose the Virtual network and subnet that you have created earlier on the AD DS. This make sure that the virtual machines within the virtual network could join the domain. Leave others as default. Click Review + Create button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6-2agZcwx17lM49R2pwlYQ.png" /></figure><p>After the validation is passed, click Create to provision the server. The deployment of the new Azure AD DS will take some time. It can take up to an hour to completely provision.</p><h3>Add user into the Azure Active Directory</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MikIKinIxiWJtYXDfzL7ZA.png" /></figure><p>Click on the + New user to add a new user.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QZHb5_lHzktc4o72I6uMVQ.png" /></figure><p>Enter an user name and key in the name.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0iU0N083JDs1Nckp3bu1UA.png" /></figure><p>Enter the initial password which will need to change later on.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/745/1*7pVu4hxtjz9ld1ScoOq0ag.png" /></figure><p>Click on the User link on the Roles section.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WimyZJofRCORH54JYLBz2w.png" /></figure><p>Select the AAD DC Administrators group and click Select. To allow a user to use Remote Desktop to connect remotely to the VM, you would need to add the user into the <em>AAD DC Administrators</em> group. Because in Azure AD DS, you don’t have <em>Domain Administrator</em> or <em>Enterprise Administrator</em> permissions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jw0ZREE16Bjlvdu5OF28Iw.png" /></figure><h4>Reset Initial Password</h4><p>This step is needed to reset the initial password for the first time login in order to be able to use to login into the domain. When a user is created in Azure AD, they’re not synchronized to Azure AD DS until they change their password in Azure AD. This password change process causes the password hashes for Kerberos and NTLM authentication to be generated and stored in Azure AD. The password hashes are needed to successfully authenticate a user in Azure AD DS.</p><p>The synchronization process is one way / unidirectional by design. There’s no reverse synchronization of changes from Azure AD DS back to Azure AD. A managed domain is largely read-only, you can’t make changes to user attributes, user passwords, or group memberships within a managed domain.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*jQw_ziWrCo8ggZWd.png" /></figure><p>To reset the initial password, open a new tab on the browser, enter <a href="https://myapps.microsoft.com/"><strong>https://myapps.microsoft.com</strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/976/1*I7xR-r6mYuGxjCQDnZF1LQ.png" /></figure><p>Enter the email of the newly added user — for e.g, user is chris, primary domain is abc.com then the email is chris@abc.com and click Next.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*edEE9bUI_HNyQB4ktvecJw.png" /><figcaption>Primary domain</figcaption></figure><p>To find the primary domain name for your current tenant, go to Azure Active Directory. On the overview page, locate the Primary domain under the Tenant information panel as highlighted above.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/1*uTjucIV5KsnQ5xLZ0WrRRA.png" /></figure><p>Key in the initial password and click Sign in.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/983/1*RiEuJfeGkhPb0c5JBR1otg.png" /></figure><p>Now, enter the new password. Remember this password to use for the user login into the Windows Server VM later.</p><p><em>Note: this manual reset password step is required because I do not have the P2 license which has the self reset password capability.</em></p><h3>Join the VM to the Managed Domain</h3><p>Navigate to the virtual machine that was created earlier. Click on the Connect button on the top.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CsP_VIOLHaCkqmlcm-LUQQ.png" /></figure><p>On the connect menu, there are several options to choose to connect to the server such as using RDP or Bastion host. In this lab, we will be using Bastion to access to the VM.</p><p><a href="https://azure.microsoft.com/en-us/services/azure-bastion/#get-started">Azure Bastion</a> is a fully managed PaaS service that provides seamless and secured RDP/SSH connectivity to the VM directly on the Azure portal over SSL.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yoZ5Fkat-XwjOrp6JyIacQ.png" /></figure><p>Click on Use Bastion button. To connect using the Azure Bastion, the virtual network must contain a subnet with the name AzureBastionSubnet with prefix of at least /27.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IlV_VR0lyMUJMp4rOuWIbw.png" /></figure><p>To do that, just click on the Manage subnet configuration link. Before we add the additional subnet for the Azure Bastion, we would need to create another address space for the virtual network.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yWmmpnjmgr2BO42NC3SJyw.png" /></figure><p>On the left menu, click on the Address space. Create another address space 10.0.10.0/27. Click Save.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xfiCQAeaTuhXEBQj6mXRJw.png" /></figure><p>Go back to the subnet section and click + Subnet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ucHrVm30k5G09HfdCKb1OQ.png" /></figure><p>Enter AzureBastionSubnet for the subnet name and enter 10.0.10.0/27 for the subnet address range. Leave others as default and click OK.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lBv_mNUN3cg3FM1s8aZuSw.png" /></figure><p>Go back to the Azure Bastion page, choose Create new for Public IP address and leave everything to default and click Create.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0aTPw5348bZM6pYDGzv4cQ.png" /></figure><p>Once is the provisioning is successful, enter the username and password for the Windows Server and click Connect.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SQlWSG_K5ZJSa7c7r2vMmw.png" /></figure><p>If the browser is activated with popup blocker, it needs to be disabled.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Wq3N5UeK_cFkJtIyKb5GYQ.png" /></figure><p>Once the remote desktop session is established. On the Server Manager, navigate to the Local Server and locate the Workgroup on the properties. Click on the <strong>WORKGROUP</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/904/1*N1eC6iy_VEfxuW-o8TEzjg.png" /></figure><p>On the System Properties dialog, click on the Change button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/713/1*FnabvQ7Yp1chtcsPcNLB7A.png" /></figure><p>Change Workgroup to Member of Domain: and enter the domain name that was created earlier in the AD DS setup.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/913/1*I2LVo7wvSda7tTe1JlkFAw.png" /></figure><p>It might prompt the above screen if the NetBIOS name is more than 15 characters, it will shorten it automatically if required. Click OK.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1010/1*vpqNNabO450Y-ZW-xBmshQ.png" /></figure><p>Enter the name and password to join the domain. Click OK.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/782/1*anr44QQiVg4jcY1WTelJsw.png" /></figure><p>If the domain join is successful, there will be a pop-up with welcome message. Click OK.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/696/1*omenaALIwI2m4aR3R9fkBA.png" /></figure><p>The VM is domain joined into the Active Directory Domain. Click OK and restart the server.</p><h3>Test Login using Domain User Credential</h3><p>To test if the domain joined server would be able to use the AD credential to login, navigate to the VM page -&gt; Overview -&gt; Connect -&gt; Bastion.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OfsNDSeOre7V6h5lfVolCQ.png" /></figure><p>Enter the AD username and password and click Connect. Once it is successful, you should be able to remote desktop into the Windows Server.</p><h3>Setup VPN Gateway on Azure (Optional)</h3><p>In this step, basically is a guide on how to setup connections between Cloud provider in a hybrid environment to showcase that both sides are able to domain-join the servers using Azure AD DS.</p><p>In order for the servers on both sides to communicate with each other, a connectivity between Cloud providers is required. This can be done via few methods, most commonly used is private dedicated line using <a href="https://azure.microsoft.com/en-us/services/expressroute/">ExpressRoute</a> or <a href="https://azure.microsoft.com/en-us/services/vpn-gateway/">site-to-site IPSec VPN Gateway</a>. In this tutorial, we will be using VPN Gateway.</p><p>Before we create the VPN Gateway, we need to allocate a subnet within an address space in the virtual network. To do that, navigate back to the vnet that was created earlier.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MLhQ2RbP7wXAJW3y4xP-0A.png" /></figure><p>On Address space settings, add another range for the VPN Gateway, for e.g. 10.0.11.0/29. Choose a range that does not overlap the other address space ranges. Click Save.</p><p>Then, navigate to the Virtual network gateway page by searching on the top bar or select from the services list</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CnExKo6K7V4xIh9_gLqmDQ.png" /></figure><p>Choose the Virtual network gateway.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qpXFGmPp_Azezjz4wyxLaw.png" /></figure><p>On the Virtual network gateways page, click on the Create virtual network gateway button or click on the Add button located on the top left of the panel.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dWYpccV66ZfmkA1L4iYe-g.png" /></figure><p>Enter a name for the virtual network gateway and choose the existing virtual network that the VM and AD DS reside. The gateway subnet address range should be automatically populated based on the newly created address space earlier.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n3BWSGnFhrIaEFdTJb3axw.png" /></figure><p>Scroll to the bottom, create a new Public IP and enter a name for it, leave others as default and click Review + create.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g0Z0L6JBdMzs9EEwPcC5-Q.png" /></figure><p>Click on the + Create new button</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cxNnFYUi-O-2XCiHIIn5aQ.png" /></figure><p>Enter the name tag for the connection, choose existing Virtual Private Gateway, choose existing Customer Gateway. Enter the CIDR block on local and the remote network CIDR which is the Azure subnet (refer to below to locate the info).</p><h4>VPC CIDR Block</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4YvQ8fdxuF5IouDsL2dvEQ.png" /><figcaption>CIDR block for VPC</figcaption></figure><p>To get the CIDR block for the existing VPC, navigate to the VPC, scroll to the right and you should see the CIDR. For e.g. in the picture above, the CIDR is 172.31.0.0/16</p><h4>Azure Virtual Network Subnet</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I8YIZH_w3fbJsAVJtU-8pA.png" /><figcaption>Virtual network address space in Azure</figcaption></figure><p>Enter the pre-shared key for the tunnel 1.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n7M4Gbn5VpdzKFUGHEuL9A.png" /></figure><p>Click Create Connection.</p><h3>Setup VPN Gateway on AWS</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vbwqVnOsb9cp-xQ6BXVv3A.png" /></figure><p>Click on the Create Customer Gateway button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CbjsQPXJ4EVRA3QzXZbFFQ.png" /></figure><p>Key in the IP Address (which is the Azure VPN Gateway Public IP address).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oMP-pIHzOCDBB9zRXqP4bQ.png" /><figcaption>Customer Gateway</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BfnfgzbdHTZOcC6tx-6gSw.png" /></figure><p>Next, we would need to Create a Virtual Private Gateway.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b07JntsmMZ5lxI6IKbbRwg.png" /></figure><p>Enter a name for the VPG and click Create Virtual Private Gateway.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BqMVZGdIX2xaj7hC4M0NRQ.png" /></figure><p>Then, attach the VPG to the existing VPC.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vjj99XboPbVWlX8vZeWtcg.png" /></figure><p>Choose the VPC from the dropdown list box and click Yes, Attach.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D8OFpZ3gFcTJifNyud0naA.png" /></figure><p>The state should be “attached” now.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v0r0rffLApb3YfpaiWaYTg.png" /></figure><p>Click on the Create VPN Connection.</p><p>Enter a name for the connection, choose Virtual Private Gateway as the target gateway type and select the existing VPG, choose Existing Customer Gateway, set the routing options to Static and specify the Azure subnet.</p><p>After the VPN is created, go to the Overview page and locate thee Public IP address. Copy this IP address so that we can use it for the VPN configuration on AWS.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*seUctmqvpEMMyOu8H_I_oA.png" /></figure><p>Scroll to the settings section and click on the Connections. Click on the + Add button to add a new site to site connection.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/871/1*A-rN6LsTZNclcbxIA9a6BA.png" /></figure><p>Give a name to the connection name, choose Site-to-Site (IPSec) for the connection type. Use the existing virtual network gateway. Key in a Shared key, this would be use to configure on the AWS side later. Choose IKEv2 as the IKE Protocol. Finally, click on Choose a local network gateway to create a new local network gateway.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8I06m_b5xUta9uOmHv5Hqw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AokjuKwcAdRmW40JHwuDKA.png" /></figure><p>Key in the AWS VPN Gateway public IP and click OK.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T8yYwH9CiT84tI0tfyr4Pg.png" /><figcaption>Locate the AWS VPN Gateway Public IP</figcaption></figure><h4>Azure</h4><p>Virtual network: 10.0.1.0/24<br>Gateway subnet address range:<strong> </strong>10.0.11.0/29<strong> </strong>(This has to sit within the virtual network)<br>Azure Public IP for VPN Endpoint: xx.xx.xx.xx</p><h4>AWS</h4><p>Virtual network: 172.31.0.0/16<strong><br></strong>AWS Public IP for VPN Endpoint:<strong> </strong>xx.xx.xx.xx</p><h4>Add Route</h4><p>Before we are able to ping each other servers, we need to add the custom routing to the route tables.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QJxn7HQHpLnGS0D7KLX-Tg.png" /></figure><p>Add in the address space from Azure into the Route Tables.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TA91Z9ONc0I5S89NDehh7A.png" /><figcaption>VPN tunnel status in AWS</figcaption></figure><p>Examine if the VPN state is available on AWS.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/883/1*89iPDrFLN1HQlrw7ZgR6gA.png" /><figcaption>VPN status in Azure</figcaption></figure><p>Check to see the the VPN status is connected in Azure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/997/1*PBImWJzYYZSrr2y3kLKJUw.png" /></figure><p>Test ping to the Azure AD DS from AWS. If the ping is successful, this means that AWS can ping to Azure. Next, we would need to do the same on AWS so that Azure can ping AWS.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*92_320J6BH0-lLpOIqTRWw.png" /><figcaption>AWS EC2 Private IP</figcaption></figure><p>First, locate the AWS EC2 private IP address.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*krDASAWsyRWLVGmFO3XAJQ.png" /><figcaption>Security Group</figcaption></figure><p>Click on the security groups.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LNzmogn_1BRR3vSSbwLqJQ.png" /><figcaption>Edit inbound rules</figcaption></figure><p>Click on the Edit inbound rules.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pgBo41jGoaqCzYQNjJYnBg.png" /></figure><p>Click Add rule and add the rule for All ICMP — IPv4 and enter 0.0.0.0/0 for the source.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7PeuOyZ1QzTtn7AZd3bSjg.png" /></figure><p>On the Azure VM, open a command prompt window and test ping the AWS EC2. If the result is successful, this means both Clouds are connected now.</p><h3>EC2 Windows Server Domain-Joined with Azure AD DS (Optional)</h3><p>This step is optional, it is a way to prove that the servers outside of Azure would be able to domain-joined on Azure AD DS.</p><p>Set local DNS server to point to the Azure AD DS private IP address.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zEvbiXPlHz34O80g53O_Jg.png" /><figcaption>Azure AD DS server IP address</figcaption></figure><p>To locate the Azure Active Directory Domain Service, click on the AD DS service instance, on the Properties page, refer to the IP addresses as highlighted above. There are two IP addresses, copy them and save somewhere and will be use it to specify on the AWS EC2 Windows server’s DNS server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/675/1*yWtJMVjEhRLW1O6HgVO0dg.png" /></figure><p>On the AWS EC2, right click on the networking icon on the bottom right on the Windows desktop.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/724/1*aRjFa4xdZF8cryrpaHPU2g.png" /></figure><p>Click on the Open Network &amp; Internet settings</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/973/1*rY4upS3EyPGAtEVOYecCDA.png" /></figure><p>On setting page, click on the Change adapter options</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/730/1*FGMbU0GfaAfua4r94piEmA.png" /></figure><p>On the Network Connections folder, right click on the ethernet adapter and click Properties.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/845/1*J1pAt_S3yw2OouNV-Od-Jw.png" /></figure><p>On the Ethernet properties dialog, click on the Internet Protocol Version 4 (TCP/IPv4).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/862/1*aLwppvOG03DERyUunIUDcQ.png" /></figure><p>Enter the both Azure AD DS private IP addresses on the DNS server addresses — Preferred DNS server and Alternative DNS server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Tece5wCgHchXGl6jXBrx4A.png" /></figure><p>Close all the windows and get back to the Server Manager. Navigate to the Local Server and click on the Workgroup link.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/934/1*i2ySzcAi54MrqAorCBHHdQ.png" /></figure><p>Click on the Change… button</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/747/1*hPb9KWC_3OqaltmYud07Yg.png" /></figure><p>Then, enter the domain name from the Azure AD DS. For e.g, xxxx.onmicrosoft.com and click OK.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1020/1*eiczoU1-pg-HoVO8QgQ-1w.png" /></figure><p>On the security prompt, key in the Azure AD username and password and click OK.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/867/1*2iuieEwd__pCQG_o4ycNyg.png" /></figure><p>After domain join is successful, you should see the above message. Click OK. And now, the Windows Server running on AWS EC2 is domain joined into the Azure AD DS.</p><p>To test remote login using the Azure AD user, right click on the RDP connection file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OrKNQukoN-WBad-50ST3CA.png" /></figure><p>Click Edit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/946/1*-JMNw7fas7VRba-Rw_fJWQ.png" /></figure><p>Check the Always ask for credentials in order to key in User name. Enter the UPN name of the Azure AD. Click Connect.</p><p>Now, this works when there is a connectivity between both sites. But what happen if the connection is not available? The user would not be able to login into the server. This is where sometimes setting up a distributed identity management system is crucial to ensure that operations are not interrupted due to technical issues. Typically, in an enterprise, there would be a local Active Directory which act as the local identity management and this could be synchronized to another site. In the next step, we would be setting up a local Active Directory Domain Services in AWS EC2 and the subsequent step is to configure AD Connect to synchronize the user data to the Azure AD.</p><h3>Setup Active Directory Domain Services on AWS</h3><p>In this step, we would be setting up a new Windows Server 2019 with Active Directory Domain Services (AD DS) and DNS server. The objective of this step is to emulate the traditional way of managing user identities using Microsoft Active Directory.</p><p>To setup a EC2 with Windows Server 2019, you can refer to <a href="https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/EC2_GetStarted.html">https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/EC2_GetStarted.html</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1uHhdtyJN8uUlX4CYLINTg.png" /></figure><p>Firstly, on the Windows Server GUI, click on the Windows icon on the bottom left of the screen and click the Server Manager.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WUF3jW_xeA2JmaxadSmTNg.png" /></figure><p>On the main page of the Server Manager, click on the “Add roles and features”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F1Ty3WeSTN6ifK9Zgto7IQ.png" /></figure><p>On the start of the Add Roles and Features Wizard, click Next &gt; to go to the next screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*inMnVnqpp7osbR5zasnKqA.png" /></figure><p>Choose the first option — “Role-based or feature-based installation”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NEId7Aau-WS6rsXTgOokFA.png" /></figure><p>On the Server Selection, it should list the default server, choose the first option and click Next &gt;.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_nE2FN7nuPee4pTIWez7Yg.png" /></figure><p>On the Server Roles section, check on the Active Directory Domain Services (ADDS).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/939/1*XN62Aj9MFR0QMlrWs3NpYA.png" /></figure><p>It will then pop-up a dialog to show the role services or features that is required to install the ADDS. Make sure the option “Include management tools (if application) is checked and click Add Features.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Aq_lTMI9i2TCQxDP3lG9YA.png" /></figure><p>After that check on the DNS Server to install DNS Service. In the DNS Server pop-up dialog, choose the default option (include management tools) and click Add Features.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/930/1*qpfjHkEvYlpB5RqjFfByWA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UPyTEtWcgjz_4gl-Ii0rpQ.png" /></figure><p>If the computer is not set to static IP address, the above warning will appear. Just ignore at the moment. Click Continue.</p><p><em>Note: The best practice especially for Production is to configure static IP so that the IP would not change and therefore will not impact clients that is connecting to the server.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yvw2ECEO6RtEDYiHXcahbw.png" /></figure><p>Click Next &gt;.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ym_o0FrOG_uygVufl_aFXw.png" /></figure><p>On this Features section, leave everything to default and click Next &gt;.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zLLbv1gUuvBM_rffWLp2_w.png" /></figure><p>On this AD DS page, click Next &gt;.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tbofBP5JUpDnLDmAhoMh7w.png" /></figure><p>Click Next &gt; at the DNS Server section to proceed to the Confirmation page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dWtET-b1Q6A2pCpXzCFA6w.png" /></figure><p>Click on the Install button to install the AD DS and DNS Server. After couple of minutes, the installation should be completed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n4LBMPiyQs6do-yM-o4mGQ.png" /></figure><p>When the installation completed, click on the link — “Promote this server to a domain controller”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S_fze-0KUjYtun5Leap0jg.png" /></figure><p>On the Deployment Configuration section, choose “Add a domain controller to an existing domain” and specify the domain name. Click Next &gt;.</p><p>Note: The root domain name of this must match on the Azure AD DS domain name in order for users to sign on using Azure AD.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mGUXD9v1hqFIBVqnXdTRHw.png" /></figure><p>Enter a password for the Directory Services Restore Mode (DSRM) password and leave others as default. Click Next &gt;.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yQ2lHzhtZFNid4LVxlp1kQ.png" /></figure><p>Uncheck the Create DNS delegation and click Next &gt;.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h0zPsAhjm9cQEfTChd5nuw.png" /></figure><p>The NetBIOS domain name would be automatically generated. Leave it as default and click Next &gt;.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kV1asR-5egMX6X6sfHhzbw.png" /></figure><p>Leave it as default for the paths and click Next &gt;.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fHNh7hsMaojKlLpstdaqDw.png" /></figure><p>At last, review the options and click Next &gt;.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s2YVtrIF3TTrHKIs3WkIDw.png" /></figure><p>After the prerequisites check is passed successfully, click the Install button. After a while, the server will be automatically restarted to finish the installation process.</p><h4>Add User to Active Directory Domain Services in AWS</h4><p>This step is to create new user into the AD DS in AWS for testing purpose later on.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/890/1*BugpH1ex4PEEt7huk5jyKw.png" /></figure><p>On the server manager, click on the Tools and choose Active Directory Users and Computers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5ezsKDAKqNE8wH0iHjjhJw.png" /></figure><p>Click on the user icon as highlighted above.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/970/1*zMPDwjF-XTwcLhwQelDE1w.png" /></figure><p>Key in the First name and User logon name (<em>note: use a different name from the Azure AD so that we can differentiate for testing</em>). Click Next &gt;.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/948/1*5WriPP45suBEWb5AKIWrpg.png" /></figure><p>On the password screen, key in the password and confirm. Click Next &gt;. On the final confirmation dialog, click Confirm.</p><h3>Setup AD Connect</h3><p>In order to synchronize the directory data on the Active Directory Domain Services in AWS to the Azure AD, we need to use a tool called <a href="https://docs.microsoft.com/en-us/azure/active-directory/hybrid/whatis-azure-ad-connect">Azure AD Connect</a>. Download the tool from the Azure or Microsoft download <a href="https://www.microsoft.com/en-us/download/details.aspx?id=47594">site</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IdQ5j9gGBxK1nw0KeR99ag.png" /></figure><p>After downloaded the AD Connect, launch the program and click Continue after checked the license terms.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZCYlUvT1TYuH8QMA8puV-Q.png" /></figure><p>Choose Express settings</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k73fxERdDUN6nWJERQ4LIg.png" /></figure><p>Click Install.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MsY2GeTRSH5aAyC6DE6aHw.png" /></figure><p>Enter the Azure AD credential and click Next.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NoIvASDs6R0kM-sQb-hxBw.png" /></figure><p>Enter the local username and password on the Active Directory Domain Services that was created in the earlier step and click Next.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x6-pA6jkXUVlDDuvjis1PA.png" /></figure><p>Click Configure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/998/1*qNz0bBUjv6HgBomo02Mikw.png" /></figure><p>Go back to the Azure, navigate to the Azure Active Directory-&gt;Users. The user that was created in AWS AD DS is now synchronized to the Azure AD. The AD Connect sync works!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IN8lAl8C2fagqCIBlrXC4g.png" /></figure><p>To double confirm if the synchronization is working correctly, navigate to the Azure AD -&gt; Azure AD Connect page. The sync status should show Enabled.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/979/1*Cz3TUjmx2rfjiMIhQHqDuw.png" /></figure><p>To use the replicated user credential from AWS to login into the domain-joined VM, you would need to add the user into the <em>AAD DC Administrators</em> group. Because in Azure AD DS, you don’t have <em>Domain Administrator</em> or <em>Enterprise Administrator</em> permissions. Only members of this group can use Remote Desktop to connect remotely to domain-joined VMs.</p><p>To do that, navigate to the Groups and click Add Memberships, select the AAD DC Administrators group and click Select.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cme7WaQMYea7ZuaKac7JgA.png" /></figure><p>Finally, go back to the VM page, connect to the VM via the Bastion, enter the credentials and click Connect. After the successful authentication you should be able to remote desktop into the VM using the replicated user from AWS!</p><h3>Summary</h3><p>This configuration should not only limited to connect to different Cloud providers but also to connect to on-premise environments. With this cross hybrid identity management in-placed, organizations are now able to work on their preferred infrastructure and yet to be able to collaborate and integrate to various of business units or departmental units or even to external parties that are using non-AD authentication by using B2C identity management such as <a href="https://azure.microsoft.com/en-us/services/active-directory/external-identities/b2c/">Azure Active Directory B2C</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1ecc672bfd40" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Create API using Azure Function with Python and Azure Cosmos DB]]></title>
            <link>https://evan-wong.medium.com/create-api-using-azure-function-with-python-and-azure-cosmos-db-afda09338d82?source=rss-2645220b89c6------2</link>
            <guid isPermaLink="false">https://medium.com/p/afda09338d82</guid>
            <category><![CDATA[azure-functions]]></category>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[azure-cosmos-db]]></category>
            <category><![CDATA[visual-studio-code]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Evan Wong]]></dc:creator>
            <pubDate>Wed, 04 Nov 2020 13:23:17 GMT</pubDate>
            <atom:updated>2021-10-22T01:42:12.988Z</atom:updated>
            <content:encoded><![CDATA[<h3>Build API using Azure Function with Python and Azure Cosmos DB</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/952/1*EXQGr0N916cnrQRM-haEnw.png" /></figure><h3>Introduction</h3><p>Serverless technologies is a valuable approach for rapid development and cost optimization.</p><p>A <a href="https://en.wikipedia.org/wiki/Serverless_computing">serverless computing</a> doesn’t mean <em>no server</em>. The code still runs on a server, but you don’t need to care as much about the underlying infrastructure because a third-party service like a Cloud provider will handle it for you. This leads to less time in operations and more time for developing software.</p><p>Serverless typically follows a pay-per-execution model, which means you have to pay only when your code runs. This can result in huge cost savings. Serverless also typically provide automatic scaling in real-time based on the computing resources need.</p><p>In this tutorial, we’re going to build a Serverless API using HTTP Triggers in <a href="https://azure.microsoft.com/en-us/services/functions/">Azure Functions</a> that uses a <a href="https://azure.microsoft.com/en-us/services/cosmos-db/">Azure Cosmos DB</a> as database. We’re going to build an API for a hypothetical e-commerce that stores information about products.</p><p>We’re going to build this API using Python. I’m not going to go dive into huge detail about Azure Functions and the complexities behind Azure Cosmos DB, I’ll just be keeping it simple enough to demonstrate how they can all work together to make a simplistic API.</p><h3>What is Azure Function?</h3><p>Azure Functions are small pieces of code that we can run in Azure without worrying too much about application infrastructure. One of the great advantage using Azure Function is to save cost, the charges on happen when the functions are executed. Comparing with traditional server based or container based technology, whether or not the functions are executed, the charges is based on the duration that the application servers run.</p><p>We can use specific events to trigger actions in our Functions. For this tutorial, we’ll be triggering events based off HTTP requests.</p><h3>What is Azure Cosmos DB?</h3><p>Azure Cosmos DB is a fully managed globally distributed NoSQL database. It provides schema agnostic capabilities for developers to develop modern applications. Azure Cosmos DB elastically scale the provisioned throughput and storage for your Cosmos databases based on your need and pay only for the throughput and storage you need. This leads to significant cost savings.</p><p>For those who are familiar with MongoDB, Azure Cosmos DB implements the wire protocol for MongoDB. This implementation allows transparent compatibility with native MongoDB client SDKs, drivers, and tools. Azure Cosmos DB does host the MongoDB database engine.</p><h3>Outline</h3><p>In this tutorial, we would be doing the following steps:</p><ol><li>Create a new Cosmos DB account and container.</li><li>Create a new Azure Function using Visual Studio Code and test.</li><li>Develop the two APIs — CreateUser and GetUsers</li><li>Deploy the two functions to the Azure Function</li></ol><h3>Prerequisites:</h3><ol><li>Azure account and a valid subscription —<a href="https://portal.azure.com/"> https://portal.azure.com</a></li><li>Visual Studio Code with the following extensions — Azure Functions, Azure Account and Python. Download VS Studio Code <a href="https://code.visualstudio.com/download">here</a></li><li><a href="https://www.python.org/downloads/">Python 3.8</a></li><li><a href="https://docs.microsoft.com/en-us/cli/azure/install-azure-cli">Azure CLI</a> version 2.4 or later</li><li><a href="https://docs.microsoft.com/en-us/azure/azure-functions/functions-run-local?tabs=windows%2Ccsharp%2Cbash">Azure Functions Core Tools</a></li><li>Source codes — <a href="https://github.com/echoesian/azure-function">https://github.com/echoesian/azure-function</a></li></ol><h3>Create new Azure Cosmos DB account</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GdKIkMarw5yf7x-3aEdMvw.png" /></figure><p>Create a Azure Cosmos DB Account on the Azure portal. Enter an account name for the Cosmos DB and leave other options as default. Click Review + Create.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oKwV_mhLJtbcxv7m6Z174Q.png" /></figure><p>After the validation is successful, we can click on the Create button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0QuJusjtHEtEYvBPqmDIZw.png" /><figcaption>Cosmos DB account deployment in progress</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ghdrkxj-KhGhLaJxlCwRBA.png" /></figure><p>After the Cosmos DB account deployment is successful, you can click on the <em>Go to resource</em> button</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pWRGOV1FV_xLPcns7iITPw.png" /></figure><p>On the Overview page, click ‘Add Container’ button to create new container.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/929/1*iVRYdGFPS4Nsx0vw7Xo3tQ.png" /></figure><p>Key in the Database id (<em>serverless-db</em>), Container id(<em>user</em>) and the Partition key (can use the /id as partition key). Remember the Database id and Container Id because we would be using on the later part of the tutorial. Click OK.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e6kIYfAbO_TO_CAYMi62TQ.png" /></figure><p>After the successful creation of the container and database, it should appear on the Data Explorer view.</p><h3>Create new Azure Function</h3><p>To create a Function in Azure, there are few ways to do it. One of the simplest way is to create functions on the Azure portal. In this tutorial, we will be using Visual Studio Code as the integrated development environment (IDE) for Azure Function codes development.</p><p>Let’s start coding! Open up the Visual Studio Code. Make sure all the required extensions on the prerequisites section have been installed.</p><h4>Sign in to Azure</h4><p>Once the Functions extension is installed, sign into your Azure account by navigating to the <strong>Azure: Functions</strong> explorer, select <strong>Sign in to Azure</strong>, and follow the prompts.</p><p>After signing in, verify that you see the email account of your Azure subscription in the Status Bar.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/891/1*sjkjX-6Rj2rjCpsdB3wLqw.png" /></figure><p>On the left pane, click on the Azure logo icon, navigate to the FUNCTIONS section and expand the subscription that you would need to deploy the Azure functions to.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/891/1*0JDOO9t5UupI5MJcLuAfcQ.png" /></figure><p>To create a new project, click on the Create New Project… icon. Browse to the directory that you wish the project to be saved to.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M96l9Q4J25JW8TbDyQtJDQ.png" /><figcaption>Local directory for the project</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oy24_6l4fZAR8vAtTX740w.png" /><figcaption>Programming language</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Pq5iMrzY_6wCpkKtAAAsRw.png" /><figcaption>Project template</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Qlrii9TeWbHtDFHUSyKOhg.png" /><figcaption>Function name</figcaption></figure><p>Then, choose Python as the programming language and HTTP trigger as the template for the first function. Provide a function name such as CreateUser for the HTTP trigger function or leave the default name.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KL-ot0F8kXEebPhIU3y5Mg.png" /></figure><p>Choose Anonymous for the authorization level. This is for testing purpose only and it is not recommended for Production usage. For Production, it is recommended to at least use Function as the authorization level.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lxMUeroRR_8a4OjVDWjnFg.png" /></figure><p>Go back to the Explorer tab, the project files should be created.</p><h4>Test Locally</h4><p>Let’s do a simple test to make sure the default function is working properly. The Azure Function Core Tools lets you run your functions on your local computer. You can start the Function app either through VS Code or through the command line interface.</p><p>To run the Function app through VS Code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V-HTvcePOiJq4-jWdEHLag.png" /></figure><p>On the top menu, navigate to the Run-&gt;Start Debugging.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R-u6f3wvZolDdXlMLVr_9Q.png" /></figure><p>If everything is running successful, you should see a URL generated for the HTTP trigger. Hold Ctrl+click (Cmd+click on macOS) on the URL. A browser page would be automatically loaded and you should see the response as below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9sMgmWGlHb6anvC5t7MJ1w.png" /></figure><p>Try to pass in a name query string to the URL by pasting the below. Replace the [YourName] with your name.</p><blockquote>?name=[YourName]</blockquote><p>For the full link example: <a href="http://localhost:7071/api/HttpTrigger?name=Evan">http://localhost:7071/api/HttpTrigger?name=Evan</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gO33VswrzFnUytwhhXjEQg.png" /></figure><p>This time, the response would be accepting your GET query string and it will output “Hello, …”. You can also test by using <em>curl</em> command or any other REST client software such as <a href="https://www.postman.com/">Postman</a>.</p><p>At this stage, your sample hello world function is working correctly locally on your computer.</p><h3>Code APIs</h3><p>In this step, we will develop two APIs for the hypothetical e-commerce — one for creating a new user and another to list all available users in the system. Let’s code the first API</p><h4>Create User API</h4><p>We will be using Cosmos DB as the NoSQL database to store users data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Nel9RcFa_iB2yI_6JzhgJw.png" /></figure><p>First, if the container has not been created initially, create the user container under the existing <em>serverless-db</em> database. On the Cosmos DB service page, click on the <em>Data Explorer, </em>on the <em>serverless-db</em>, click on the triple-dot button (…), click on “New Container” on the pop-up menu.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/913/1*iSS0EvUnum_TPbjVsFAerQ.png" /><figcaption>Cosmos DB — Create Container</figcaption></figure><p>Use existing database, and enter user as the Container id. Key in “/id” as the Partition key.</p><p>Back to the Visual Studio Code, download and import the source codes from my <a href="https://github.com/echoesian/azure-function">github repo</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/558/1*B3T_kkRUpaQeT93lHIFcoA.png" /></figure><p>Once the import is successful, you should see the directory structure like above.</p><h4>Cosmos DB Connection String</h4><p>First step is to change the Cosmos DB connection string to refer to your actual Azure Cosmos DB primary connection string. To find the connection string, go to the Azure portal, navigate to the Cosmos DB service. Click on the keys on the left menu.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-bzHnrQwPFV6S0eLO8hxTQ.png" /><figcaption>Cosmos DB — Primary Connection String</figcaption></figure><p>Look for the PRIMARY CONNECTION STRING, copy the entire string. Go back to Visual Studio Code, open the <em>local.settings.json</em> file located at the root of the project folder.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a2e694c32206ee16d7b21e38cd6900fa/href">https://medium.com/media/a2e694c32206ee16d7b21e38cd6900fa/href</a></iframe><p>Locate the parameter “AzureCosmosDBConnectionString”, update the value to the Cosmos DB primary connection string that you have copied earlier.</p><p>Let me explain on the codes, since we are implementing a HTTP trigger, the input of the function would be a GET or POST request.</p><blockquote>def main(req: func.HttpRequest, doc: func.Out[func.Document]) -&gt; func.HttpResponse:</blockquote><p>The Python code accept the request via HttpRequest and output as Cosmos DB binding and respond as HttpResponse.</p><blockquote>name = req.params.get(‘name’)</blockquote><p>Next, it would get the value of the name query string from the request.</p><blockquote>newdocs = func.DocumentList()</blockquote><p>Next, initialize a new DocumentList. After that, initialize a new dictionary and populate new ID and the user name. Id is randomly generated using the built-in uuid function. The dictionary will then append into the DocumentList. It then persist into the database using the set function.</p><blockquote>doc.set(newdocs)</blockquote><blockquote>return func.HttpResponse(f”User {name} created successfully.”)</blockquote><p>Finally, send the HTTP response as a customized message like above.</p><p>You will also need to verify if the settings on the Cosmos DB binding is correctly set. Open the function.json inside the CreateUser function project folder.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/434fb43ba74894f3c68235d2462a6136/href">https://medium.com/media/434fb43ba74894f3c68235d2462a6136/href</a></iframe><p>Locate the “databaseName”, this parameter should point to the actual database name that you have created in the earlier part of the tutorial.</p><h4>Test Create User Function</h4><p>Now, to test the function, click on the Run-&gt;Start Debugging.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6FOAeLiSftY5GuVZpe1BcQ.png" /><figcaption>Local CreateUser API URL</figcaption></figure><p>Use a REST client to exaecute the request using the link provided.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yBBykKjdGjhjcjxs4-dldA.png" /></figure><p>By default, if there is no name specified as the query string, the response would be look like the above. Let’s put in the name query and try again.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ffCVMUQiSS4bq4d0dKWp3w.png" /></figure><p>This time, the message should indicate that the new user is created. Let’s verify if the user has been created in the Cosmos DB. Switch to the Azure portal and navigate to the Cosmos DB service page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kGzc1jtvDr-KKxFTLT4tAQ.png" /></figure><p>On the Data Explorer page, select the <em>serverless-db</em> and click on the <em>user </em>container and choose <em>Items</em>. On the right page, click on the last row of the items, you sould see the new user data. It works!</p><h4>List Users API</h4><p>Now, let’s create another API to retrieve all the users data.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b7cdf936c42d3afb135259eb89ac99e5/href">https://medium.com/media/b7cdf936c42d3afb135259eb89ac99e5/href</a></iframe><p>Let’s inspect the function.json file, notice the direction is “in” because we are using the input binding for Cosmos DB. There is also a new parameter — sqlQuery, this is the select query to get all the users.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0a7c006c0c1bfb1c5e6ea8a5de700cb6/href">https://medium.com/media/0a7c006c0c1bfb1c5e6ea8a5de700cb6/href</a></iframe><p>Open up the __init__.py file, the main function remains the same where it accepts incoming request as HTTP request and output as HTTP response. For this API, the input binding would get all the user data. The first step is to initialize an array to store all the users data. Secondly, loop through the DocumentList, create user object by assigning the value to the id and name respectively. Lastly, it will append to the array.</p><p><em>return func.HttpResponse(<br>json.dumps(users_json),<br>status_code=200,<br>mimetype=”application/json”)</em></p><p>The return would be the JSON array of the users data.</p><h4>Test List Users Function</h4><p>Switch back to the Visual Studio Code, while the debugging session is still open now, we can Ctrl+Click (cmd+Click on Mac) to execute the function within the browser.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R_tC54gwA1It_TLRP-nnrA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PzY1Nx8MaWhDaUgjjOgBaw.png" /></figure><p>The response would looks something like the above.</p><h3>Deploy the Functions to Azure</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A2eiYLU-JyQmeNqi-m-U3w.png" /></figure><p>Go to Azure and click on “up arrow” button to deploy the functions. Choose the subscription that you want the functions to deploy to.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GCJ5ao7OiFF6fmiJHiFt1A.png" /></figure><p>Click<em> “Create new Function App in Azure…”</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VjRF4eFA566oehIl7vHvaA.png" /></figure><p>Enter a function app name such as <em>serverless-python</em> (You should use any other name as the name has to be a globally unique name).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FqdPWarMwTnT0R9QUo_l_g.png" /></figure><p>Choose Python 3.8</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0HeMJg11aS1cM5e6XUiERg.png" /></figure><p>Choose the region.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/520/1*f6rdakR-UNx2xf5TqgFClA.png" /></figure><p>Wait for a couple of minutes…From my experience, the functions should be deployed to Azure within 3 minutes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/533/1*w9X4iJk1ldqRk3lLXMImgA.png" /></figure><p>Once it is deployed, on the Azure pane, we should see two functions displayed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Sw2FMFWoQN5iazjgEcNOHg.png" /></figure><p>By default, the Azure Functions extension does not deploy the Cosmos DB connection string from the local.settings.json. So, we would need to manually add the connection strings on the Azure Function configuration page. On the configuration page, click on the <em>“+ New connection string” </em>button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7hARZYUfg-vB5OFZJA-N6Q.png" /></figure><p>Enter the name “AzureCosmosDBConnectionString” and the value if the primary connection string that we can get from the local.settings.json file or the keys from the Cosmos DB service page. Click OK.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*79ZuyxwtlLSnGoJFaTf9PA.png" /></figure><p>Click on the Save button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2jWa3GjVNfz_H_3yyvA6ug.png" /></figure><p>Click Continue. The function app is now successfully deploy to the Azure.</p><h3>Test Functions on Azure</h3><p>There are several ways to test the functions including using a browser, REST client or Azure portal. In this step, we will be testing the two functions on Azure portal.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ktXja6h1pgvjT3r4qJsA0A.png" /></figure><p>Navigate to the Functions page. Click on the CreateUser function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tSoI9Fqk4yFOeZa-Wv4Aug.png" /></figure><p>On the <em>Code + Test</em> page, Click on the<em> Test/Run</em> button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QvbGjUGi6VQ-A3d_7_7Esw.png" /></figure><p>On the input section, add the name parameter with a value. Click Run.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2voy8SylZVAWIvPHwL9VIg.png" /></figure><p>If it is successful, we should be getting 200 OK response and the response message. To verify the function, go back to the function page and click on the GetUsers function. Similarly, click on the Test/Run button and click Run.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*p0dRkRrooHJEaywihmL9hA.png" /></figure><p>The newly created user should appear on the last record of the collection.</p><p>On the next topic, I’ll be expanding the scope of the project to use API Management capabilities to secure and govern the APIs. Subsequently, I’ll be covering the concept of DevOps to streamline the process of continuous integration and continuous deployment using the same project. Stay tuned and enjoy!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=afda09338d82" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why JBoss Fuse for Microservices?]]></title>
            <link>https://evan-wong.medium.com/why-jboss-fuse-for-microservices-4d6a2b709b70?source=rss-2645220b89c6------2</link>
            <guid isPermaLink="false">https://medium.com/p/4d6a2b709b70</guid>
            <category><![CDATA[integration]]></category>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[red-hat-openshift]]></category>
            <category><![CDATA[jboss]]></category>
            <category><![CDATA[apache-camel]]></category>
            <dc:creator><![CDATA[Evan Wong]]></dc:creator>
            <pubDate>Fri, 23 Oct 2020 02:25:30 GMT</pubDate>
            <atom:updated>2020-10-23T02:25:30.197Z</atom:updated>
            <content:encoded><![CDATA[<h3>What is Microservices?</h3><p>Microservices is a variant of the <a href="https://en.wikipedia.org/wiki/Service-oriented_architecture">service-oriented architecture</a> (SOA) architectural style that structures an application as a collection of <a href="https://en.wikipedia.org/wiki/Coupling_(computer_programming)">loosely coupled</a> services. In a microservices architecture, services should be <a href="https://en.wikipedia.org/wiki/Service_granularity_principle">fine-grained</a> and the protocols should be lightweight.</p><h3>Can I build Microservices application without JBoss Fuse?</h3><p>You could use variety of frameworks to build micro services application. One of the popular frameworks is Spring Boot. Spring-Boot is one of the top trending frameworks in the <em>Microservices</em> era, one of the fundamental building blocks for creating cloud enabled applications, at least in the Java universe. However, application framework is just a small component in the entire process of developing and rolling out a Microservices application. Below are some of the key questions one shall consider for a complete Microservices development and deployment lifecycle:</p><ul><li>How do you integrate among the services?</li><li>How do you monitor the health of the services?</li><li>How do you manage the dependencies of the services?</li><li>How do you scale the services?</li><li>How do you maximize the reusability of the services?</li></ul><h3>Why use JBoss Fuse to develop Microservices application?</h3><p>JBoss Fuse facilitates developers in the process of developing Microservices application by providing the end to end platform with capabilities:</p><blockquote>i. Visual Development — Make developer’s life easier by giving visual development using graphical IDE which includes graphical data transformation mapping, routing and orchestration.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*DJvMgUeptNjklA-Z" /></figure><blockquote>ii. Pattern-Based Service Implementation — By leveraging on the Apache Camel framework, it provides service implementation using different languages to define routes and patterns.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/634/0*bIGng4O7gIrX6TqQ" /></figure><blockquote>iii. Service Contracts and Binding — Using CXF to automatically generates endpoint definition from WSDL. Supports REST/JSON binding in Java and helps to generate Swagger documentation</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*A3l1E4rNll4OzL6Q" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*aBTU4Pdz6bJqRtyS" /></figure><blockquote>iv. Scalability — In Microservices world, the ability to scale the applications automatically is a very critical capability. Fuse applications can be containerized and run on OpenShift Container Platform to achieve highly available and scalable environment.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*9v8XES_RstSg1-S8" /></figure><blockquote>v. Integration at Scale — Microservices tends to grow in number of services. The big challenge is how does these large scale of services to be able to manage and monitor under a centralized management system. Fuse comes with Fabric8 which allow operators/administrators to be able to simply manage the large and distributed Fuse deployments.</blockquote><p>References:</p><ol><li>Microservices Definition — <a href="https://en.wikipedia.org/wiki/Microservices">https://en.wikipedia.org/wiki/Microservices</a></li><li>Camel Integration Patterns (EIP) — <a href="http://camel.apache.org/enterprise-integration-patterns.html">http://camel.apache.org/enterprise-integration-patterns.html</a></li><li>Microservices with Red Hat JBoss Fuse — <a href="https://www.redhat.com/cms/managed-files/3.Microservices%20with%20Red%20Hat%20JBoss%20Fuse%20%20Alexy%20Brook%2C%20CTO%20of%20Java%20%26%20Integration%20Solutions%20Sub-Division%2C%20Matrix%20Integration%20%26%20SOA%2C%20Center%20of%20Excellence.pdf">https://www.redhat.com/cms/managed-files/3.Microservices%20with%20Red%20Hat%20JBoss%20Fuse%20%20Alexy%20Brook%2C%20CTO%20of%20Java%20%26%20Integration%20Solutions%20Sub-Division%2C%20Matrix%20Integration%20%26%20SOA%2C%20Center%20of%20Excellence.pdf</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4d6a2b709b70" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>