<?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 Hants Williams on Medium]]></title>
        <description><![CDATA[Stories by Hants Williams on Medium]]></description>
        <link>https://medium.com/@hantsawilliams?source=rss-4726d4325967------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*PB4ZuPCzzO044haAxnzehw.jpeg</url>
            <title>Stories by Hants Williams on Medium</title>
            <link>https://medium.com/@hantsawilliams?source=rss-4726d4325967------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 03:26:41 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@hantsawilliams/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[Medical codexes you should know as a health informaticist]]></title>
            <link>https://medium.com/@hantsawilliams/medical-codexes-you-should-know-as-a-health-informaticist-41606ff32cbc?source=rss-4726d4325967------2</link>
            <guid isPermaLink="false">https://medium.com/p/41606ff32cbc</guid>
            <category><![CDATA[health-informatics]]></category>
            <category><![CDATA[medical-coding]]></category>
            <dc:creator><![CDATA[Hants Williams]]></dc:creator>
            <pubDate>Fri, 21 Jul 2023 13:30:56 GMT</pubDate>
            <atom:updated>2023-07-21T13:36:25.036Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/481/1*8l7TPW08qT4myYnVcDNcMw.jpeg" /><figcaption>medical codexes</figcaption></figure><p>Let’s talk about some important medical codexes that you’ll come across quite often in your work. Don’t worry if you’ve never heard the word “codex” before — it’s just a fancy word for a set of rules or guidelines.</p><p>Medical codexes are critical for healthcare professionals as they provide us with a standard, interoperable language to communicate and share critical information with one another. At first glance they can look intimidating, but with time you will likely grow to love them and see their value (for the most part).</p><p>Now, let’s dive in:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/21374b3fcbbe40db43cb334f59106bfe/href">https://medium.com/media/21374b3fcbbe40db43cb334f59106bfe/href</a></iframe><p>So, there you have it. As a health informaticist, understanding these codexes is vital for your work. They help organize and standardize medical data, making it easier to analyze, share, and provide quality care to patients.</p><p>Remember, these codexes are just tools to help us in our important work. They might seem complicated at first, but with practice and experience, you’ll become familiar with them.</p><p>*Last updated: 2023–07–01*</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=41606ff32cbc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Fast API and Data Dog: Simple Logging Approach]]></title>
            <link>https://medium.com/@hantsawilliams/fast-api-and-data-dog-simple-logging-approach-a07c8fe34ccd?source=rss-4726d4325967------2</link>
            <guid isPermaLink="false">https://medium.com/p/a07c8fe34ccd</guid>
            <category><![CDATA[fastapi]]></category>
            <category><![CDATA[datadog]]></category>
            <category><![CDATA[logging]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Hants Williams]]></dc:creator>
            <pubDate>Sun, 19 Feb 2023 17:30:08 GMT</pubDate>
            <atom:updated>2023-02-19T17:30:08.510Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/642/1*0zeNhwDbWEWgUEniq8Retw.png" /></figure><p><em>TLDR: clone the </em><a href="https://github.com/hantswilliams/fastapi-datadog"><em>github repo</em></a><em> and start using datadog for logging your fastAPI application without a datadog agent</em></p><h3>Logging our data…</h3><p>How do we capture our terminal/uvicorn output and all other logs so we can share and learn from them?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/588/1*lSUNw7y4JwBqPPEqxUZMqQ.png" /></figure><p>In this tutorial, we will be exploring how to use FastAPI and Datadog for logging in your Python web applications. While the Datadog agent is a popular way to send logs to Datadog, it may require additional knowledge and access to the OS that not everyone has or wants. Instead, we will show you how to use the <a href="https://pypi.org/project/datadog-api-client/">Datadog API client</a> to directly send logs to Datadog without the need for the agent. By the end of this tutorial, you will have a good understanding of how to implement logging in your FastAPI application and how to send those logs directly to Datadog.</p><p>Before we dive into using Datadog for logging, let’s take a look at the basic FastAPI application that we’ll be using for this tutorial. This application contains two endpoints:</p><p>The first one, which is the root page, will log both a warning and an info message and print the value of an environment variable to the console.</p><pre>@app.get(&quot;/&quot;)<br>def read_root():<br>    logger.warning(&quot;Handling root request&quot;)<br>    logger.info(&#39;ENV: {}&#39;.format(os.getenv(&#39;ENV&#39;)))<br>    return {&quot;Hello&quot;: &quot;World 3&quot;}</pre><p>The second endpoint is for handling requests for items, and will raise an HTTP exception if the item ID is 3. These two endpoints will allow us to log both console messages and user-defined error messages using the logger object from the logging_dd module.</p><pre>@app.get(&quot;/items/{item_id}&quot;)<br>async def read_item(item_id: int, q: str = None):<br>    if item_id == 3:<br>        logger.warning(&quot;Handling item request #3 doesnt like!&quot;)<br>        raise HTTPException(status_code=418, detail=&quot;Nope!! I don&#39;t like 3.&quot;)<br>    return {&quot;item_id &quot;: item_id, &quot;q&quot;: q}</pre><p>To simplify the process of launching the application, we have included the necessary arguments for Uvicorn (the ASGI server for FastAPI) within the Python script itself, so all you need to do is run python main.py to launch the app.</p><pre>if __name__ == &quot;__main__&quot;:<br>    uvicorn.run(<br>        &quot;main:app&quot;, <br>        host=&quot;0.0.0.0&quot;, <br>        log_config=None, <br>        access_log=True, <br>        use_colors=True,<br>        port=8000, <br>        reload=True)</pre><p>Now for the logging.</p><pre>from datadog_api_client import ApiClient, Configuration<br>from datadog_api_client.v2.api.logs_api import LogsApi<br>from datadog_api_client.v2.model.content_encoding import ContentEncoding<br>from datadog_api_client.v2.model.http_log import HTTPLog<br>from datadog_api_client.v2.model.http_log_item import HTTPLogItem</pre><p>We have created a simple python file that contains all the logging information calledlogging_dd.pyin the repo (utils/logging_dd.py). The primary package we are using is the <a href="https://pypi.org/project/datadog-api-client/">Datadog API client</a>. This Python package that provides an easy-to-use API that will allow us to logs to Datadog without the need for the Datadog agent. This makes it an ideal choice for basic logging needs where additional features such as advanced tracing are not required. Some advantages of using the Datadog API client over the Datadog agent include simpler configuration and setup, as well as lower resource requirements, since the client does not require a dedicated agent running on the host machine. Additionally, using the API client allows for more flexibility and control over the logging process, since it is possible to customize the format and content of the logs being sent to Datadog.</p><p>We are then using a .env file to store the information that we need to get things connected:</p><ul><li>DD_LOGGING_ENV: This variable specifies the environment in which the application is running. This can be useful for organizing and filtering logs in Datadog based on the environment. For example, you could use different values for DD_LOGGING_ENV for your development, staging, and production environments.</li><li>DD_API_KEY: This variable specifies the API key that is used to authenticate the API client when sending logs to Datadog.</li><li>DD_HOSTNAME: This variable specifies the hostname that is associated with the logs being sent to Datadog. This can be useful for identifying the source of the logs, especially in cases where multiple hosts are sending logs to the same Datadog account.</li><li>DD_SERVICE: This variable specifies the name of the service that is associated with the logs being sent to Datadog. This can be useful for grouping related logs together and for filtering logs by service name in the Datadog UI.</li></ul><p>Great now lets review what else is inside this file:</p><p>1. Loading in our config values</p><pre># Set up the Datadog API client<br>config = Configuration()<br>config.api_key[&#39;DD-API-KEY&#39;] = os.getenv(&quot;DD_API_KEY&quot;)<br>print(&#39;DD_API_KEY: &#39;, os.getenv(&quot;DD_API_KEY&quot;))<br>config.host = &#39;https://http-intake.logs.datadoghq.com&#39;<br>api_client = ApiClient(configuration=config)<br>logs = LogsApi(api_client)</pre><p>2. Setting up our basic logging to capture everything (DEBUG) and save things to a app.log file locally (this is in addition to what we will be doing shortly that saves it all to datadog as well):</p><pre>logging.basicConfig(<br>    level=logging.DEBUG,<br>    format=&quot;%(asctime)s [%(process)d] [%(levelname)s] %(message)s&quot;,<br>    handlers=[<br>        logging.FileHandler(filename=&quot;./app.log&quot;, mode=&quot;w&quot;),<br>        logging.StreamHandler(sys.stdout)<br>    ]<br>)</pre><p>3. Custom logging handler: This code below defines a custom logging handler, DatadogHandler, which extends the base logging.Handler class. The DatadogHandler class overrides the emit() method to format the log data into a JSON object and sends it to Datadog using the Datadog Logs API. The method also updates the log level to &#39;ERROR&#39; if the log message contains certain keywords or if the log message contains any number between 400 and 599. This custom handler allows logs to be sent to Datadog with the custom format and details we defined, which will be useful in searching, filtering, and analyzing logs.</p><pre>class DatadogHandler(logging.Handler):<br>    def emit(self, record):<br>        # # Ignore debug messages<br>        # if record.levelno == logging.DEBUG:<br>        #     return<br><br>        # if record.getMessage() contains the word error, errors, or exception, set the log level to error<br>        if &quot;error&quot; in record.getMessage().lower() or &quot;exception&quot; in record.getMessage().lower():<br>            record.levelname = &quot;ERROR&quot;<br><br>        # if record.getMessage() contains any number between 400 and 599, set the log level to error<br>        if any(str(x) in record.getMessage() for x in range(400, 600)):<br>            record.levelname = &quot;ERROR&quot;<br><br><br>        toJson = json.dumps(<br>            {<br>                &quot;python-logging&quot;: {<br>                    &quot;py-env&quot;: os.getenv(&quot;DD_LOGGING_ENV&quot;),<br>                    &quot;py-message&quot;: record.getMessage(),<br>                    &quot;py-status&quot;: record.levelname.lower(),<br>                    &quot;py-logger&quot;: record.name,<br>                    &quot;py-stacktrace&quot;: record.exc_info,<br>                    &quot;py-exception&quot;: record.exc_text,<br>                    &quot;py-line&quot;: record.lineno,<br>                    &quot;py-file&quot;: record.filename,<br>                    &quot;py-function&quot;: record.funcName,<br>                    &quot;py-level&quot;: record.levelno,<br>                    &quot;py-path&quot;: record.pathname,<br>                    &quot;py-thread&quot;: record.thread,<br>                    &quot;py-threadName&quot;: record.threadName,<br>                    &quot;py-process&quot;: record.process,<br>                    &quot;py-processName&quot;: record.processName,<br>                    &quot;py-args&quot;: record.args,<br>                    &quot;py-msecs&quot;: record.msecs,<br>                    &quot;py-relativeCreated&quot;: record.relativeCreated,<br>                    &quot;py-created&quot;: record.created,<br>                    &quot;py-module&quot;: record.module,<br>                }<br>            }<br><br>        )<br><br>        # Send the log to Datadog using the Logs API<br>        try:<br>            body = HTTPLog(<br>                [<br>                    HTTPLogItem(<br>                        ddsource=&quot;Python&quot;,<br>                        ddtags=&quot;env:{}&quot;.format(os.getenv(&quot;DD_LOGGING_ENV&quot;)),<br>                        hostname=&quot;{}&quot;.format(os.getenv(&quot;DD_HOSTNAME&quot;)),<br>                        message= toJson,<br>                        service=&quot;{}&quot;.format(os.getenv(&quot;DD_SERVICE&quot;)),<br>                        status=record.levelname.lower()<br>                    ),<br>                ]<br>            )<br><br>            logs.submit_log(content_encoding=ContentEncoding.DEFLATE, body=body)<br>            # print(response)<br><br>        except Exception as e:<br>            print(f&quot;Error sending log to Datadog: {e}&quot;)</pre><p>In the toJson dictionary, we&#39;re using record.getMessage() to capture the log message and record.levelname to get the logging level. We&#39;re then setting additional key-value pairs in toJson that correspond to other properties of the LogRecord, such as the logger name (record.name) and the line number (record.lineno). By including this contextual information in the log, we can more easily identify and diagnose issues in our code.</p><p>Lastly, we set up the logger for the Uvicorn web server to use.</p><pre>logger = logging.getLogger(&quot;uvicorn&quot;)<br>logger.info(&#39;Starting the app logging...&#39;)<br>logger.addHandler(DatadogHandler())</pre><p>It first creates a logger object named uvicorn. It then adds a new handler to the logger using the addHandler() method. The handler used here is the DatadogHandler class that we defined earlier, which sends logs to Datadog using the Datadog Logs API.</p><p>After adding the new handler, the code logs an initial message at the INFO level to indicate that the logging has started. From this point on, any log messages generated by Uvicorn will be captured by the DatadogHandler and sent to Datadog.</p><p>Github repo: <a href="https://github.com/hantswilliams/fastapi-datadog">https://github.com/hantswilliams/fastapi-datadog</a></p><h3>Thats it!</h3><p>To summarize → in this exercise we set up a custom logging handler, DatadogHandler, that allows us to send structured log data to Datadog using the Logs API. We configured the handler to parse the log messages and extract relevant information to be structured into JSON format, which is then sent to Datadog for processing. We then added the custom handler to the logger that Uvicorn uses and tested our implementation by running the app and checking the logs on the Datadog platform. By utilizing this approach, we can quickly and easily set up a logging system that sends structured logs to Datadog, without the need for an agent or complex configurations. This approach is ideal for getting a production-ready logging system in place for FastAPI services or any other Python application that requires logging. The structured logs provided by this method can be used to improve monitoring, troubleshooting, and debugging of applications.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a07c8fe34ccd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Sharable Data Informatics: AWS Quicksight with Wordpress]]></title>
            <link>https://medium.com/data-science/sharable-data-informatics-aws-quicksight-with-wordpress-4f5793469123?source=rss-4726d4325967------2</link>
            <guid isPermaLink="false">https://medium.com/p/4f5793469123</guid>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[aws-quicksight]]></category>
            <category><![CDATA[wordpress]]></category>
            <category><![CDATA[information-architecture]]></category>
            <dc:creator><![CDATA[Hants Williams]]></dc:creator>
            <pubDate>Fri, 10 Apr 2020 23:03:07 GMT</pubDate>
            <atom:updated>2020-04-12T02:41:54.509Z</atom:updated>
            <content:encoded><![CDATA[<h4>Learn how to use AWS Quicksight with Wordpress</h4><h3>Why use Wordpress with AWS Quicksight?</h3><p><a href="https://wordpress.org/">Wordpress</a> is arguable the simplest and most downloaded content management platform (CMS) platform, and enables anyone to quickly build a website and display content within a few minutes.</p><p>And what about Amazon Web Services <a href="https://aws.amazon.com/quicksight/">(AWS) Quicksight</a>? Simply put Quicksight is a fully managed data visualization solution. Its competitors are Tableau, Looker, Domo, qLik, SiSense, and Microsoft Power BI to name a few. You write very little code, mostly use a GUI with drag and drop, and do not have to manage any servers, security, backups, etc….</p><p>It offers a simple user dashboard that provides you the capability to create a variety of different visualizations, <strong>edit data on the fly</strong>, bring in data from a variety of different sources (mySQL, postgres, csv/xls/.json, presto, spark, etc…) in addition you can use <strong>prebuilt 3rd party connectors</strong> (Salesforce, github, Twitter, Jira, Snowflake, and more), has out of the box compliance<strong> </strong>(<a href="https://aws.amazon.com/compliance/services-in-scope/"><strong>HIPAA and HITRUST</strong></a>), and can be easily (???) embedded in other applications.</p><blockquote>Because I work within healthcare, AWS quicksight is a no brainer to try because it is compliant with HIPAA &amp; HITECH, and is highly scalable.</blockquote><h3>What are you going to learn today?</h3><p>In the following post I am going to walk through (high level) how to connect a demo AWS Quicksight dashboard into a Wordpress instance.</p><p>This will leave you with a solid MVP. You should have some familiarity with Wordpress (PHP, HTML), AWS (IAM policies), SSH (navigating around the terminal) to follow the steps.</p><ul><li>Part 1: Getting a server with <strong>Wordpress</strong> up and running</li><li>Part 2: Getting AWS <strong>Quicksight</strong> setup and <strong>publishing a dashboard</strong> with dummy data</li><li>Part 3: Configuring <strong>IAM credentials</strong> in AWS so we can programmatically access AWS Quicksight via our Wordpress server</li><li>Part 4: And <strong>creating some custom PHP</strong> to retrieve dynamically generated URL’s with security keys for the dashboard to display in Wordpress</li></ul><p>The tools that you will be utilizing include</p><pre><strong>## Tools/Themes Utilized for This MVP </strong></pre><pre>- INSTALLED on the Wordpress Server:  <br>  - AWS CLI 2.0<br>  - JQ <br>  - Wordpress <strong>theme</strong>: Divi (but you can choose whatever) <br>  - Wordpress <strong>host</strong>: AWS lightsail + AWS Route 53 <br>  - Wordpress <strong>plugins</strong>:<br>    - ZYZ PhP Code <br>- SERVERLESS AWS tools: <br>  - AWS IAM  <br>  - AWS Quicksight</pre><p><strong>IMPORTANT</strong> : To fully complete this tutorial you will need to have an enterprise version of Quicksight enabled. <em>AWS only allows the embedding of the dashboards within the Enterprise edition</em>. The cost for enterprise with <em>one creator will be $18.00</em> bucks per month. So if you can splurge a bit on this tutorial, do it…otherwise I recommend you still follow along as I am hopefully AWS Quicksight will release this feature soon enough to their standard plan.</p><p>Now let’s begin!</p><h3>Part 1: Getting Word Press Setup</h3><p>For getting an instance of Wordpress up and running quickly without much hassle, I recommend AWS <a href="https://lightsail.aws.amazon.com/ls/webapp/home/instances">Lightsail</a> (if you are already utilizing other AWS services). It’s very simple setup. For example, with Lightsail you do not need to configure ports like :80 or :443 like you would a EC2 instance for the site to be viewable to external viewers on the internet, and it simplifies the process for domain name management and VPCs/additional networking needs.</p><p>For our purposes, a linux platform with the Wordpress 5.3.2–3 blueprint will fit our needs. FYI / The flavor of Wordpress that AWS offers is a <a href="https://docs.bitnami.com/aws/apps/wordpress/">Bitnami image</a>.</p><p>If you are having trouble with this step, watch the video instructions <a href="https://www.youtube.com/watch?time_continue=1&amp;v=hcuL6HNm1Tw&amp;feature=emb_logo">here</a>/</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yE2zr_XDZN0jYFwuVsID6A.png" /></figure><p>After you create the image, you will want to SSH into the platform to install a couple tools. AWS makes this very simple, just HIT THE BIG BUTTON that says ‘Connect using SSH’</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OrpBYR2q1x0RiOVjIp5FeQ.png" /></figure><p>This will then open up a terminal in your web browser that we will use to install a few programs:</p><p><strong>Tool 1: AWS CLI 2.0</strong> : this is the command line tool AWS provides us to utilize their services via a terminal. You should be able to install it with two commands:</p><pre>curl &quot;https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip&quot; -o &quot;awscliv2.zip&quot;</pre><pre>unzip awscliv2.zip &amp;&amp; sudo ./aws/install</pre><p>You should now have AWS CLI setup. You can confirm that it has successfully installed by performing</p><pre>aws --version</pre><p><strong>Tool 2: JQ</strong> (https://stedolan.github.io/jq/) is a command line tool that will help us parse JSON responses from AWS CLI within the terminal. Pretty cool! Installation of this program is as simple as performing:</p><pre>sudo apt-get install jq</pre><p><strong>BONUS POINTS: </strong>To make this exercise more realistic I recommend you map a domain to your new Wordpress instance. So instead of navigating to 37.125.157.64 , you and potential users can navigate to something that is human readable like <em>ilikedatastuff.com,</em> or create a new sub-domain for a domain you already own (<em>wordpress.ilikedatastuff.com</em>).</p><p>In addition, also enable SSL. <a href="https://lightsail.aws.amazon.com/ls/docs/en_us/articles/amazon-lightsail-using-lets-encrypt-certificates-with-wordpress">Follow this tutorial if you are interested in free SSL</a> for a Bitnami powered Wordpress site on AWS Lightsail.</p><p>Lastly, you may have noticed there is the annoying Powered by Bitnami banner at the bottom right hand side of the site. To remove the banner SSH back into the server that is running Wordpress and execute the following commands:</p><pre>sudo /opt/bitnami/apps/wordpress/bnconfig --disable_banner 1 </pre><pre>sudo /opt/bitnami/ctlscript.sh restart apache</pre><p><strong>Tool 3: Insert PHP Code Snippet</strong></p><p>Now the last piece of tooling we will need to install on the Wordpress server is on the front end. Login to the admin portal of your Wordpress site (www.domainname.com/<strong>admin</strong>) with the credentials:</p><p><strong>user name</strong>: user</p><p><strong>password</strong>: the password is located in a file called bitnami_credentials on your Wordpress server. You can SSH into the folder server and do nano bitnami_credential to open it up using the nano text editing tool.</p><p>If you are having trouble with this step, watch the video instructions <a href="https://www.youtube.com/watch?time_continue=1&amp;v=hcuL6HNm1Tw&amp;feature=emb_logo">here</a>/</p><p>Now go to the Plugin section of the admin portal, and search for the <em>Insert PHP Code Snippet</em> plugin. By installing this plugin we will be able to write a little bit of custom PHP code to automate the viewing of our dashboards into Wordpress.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WrAjs49mqz2BWlw_gz2DBQ.png" /></figure><h4>Now to AWS Quicksight!</h4><h3>Part 2: Getting AWS Quicksight Setup</h3><p>When you go install AWS quicksight, the first thing you will want to do is click on the top right hand side where the person avatar is and navigate to Manage Quicksight</p><h4>Step 1: Manage Quicksight</h4><p>After enabling the Enterprise version you should see something that looks like this below, with the Edition: Enterprise.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/842/1*7YODlrcx2LECimxSPwXigg.png" /></figure><p><strong>IF YOU DO NOT SEE</strong> all of the options displayed above, that most likely means that you do not have the enterprise version of quicksight enabled and will not be able to perform dashboard embedding until it is enabled.</p><p>Now navigate to the Domains and Embedding section first.</p><p>Here, we will whitelist the name of your domain by entering the domain name that you selected with both <em>www.DOMAINNAME.com </em>as well as <em>DOMAINNAME.com </em>without the www.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PLrjqd4vI81r-g6wJno5-Q.png" /></figure><p>This will ensure that once we embed our dashboards into our site, that they will have the proper secure permissions to display. If we do not place the domain names in here, we will receive error messages related to improper viewing permissions. If you are using a subdomain, be sure to CLICK/ENABLE the checkmark box by Include Sub-domains? question.</p><h4>Step 2: Publish Dummy Data</h4><p>Luckily Quicksight already comes with a bunch of dummy data.</p><p>When you are on the home screen under <em>All Analyses </em>you will see four sets of dummy data (dashboards) that contain a variety of different charts.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1PTMfQUtIUzuNt5GgCwz7w.png" /></figure><p>Pick whichever one you want. To publish, once you have selected the dashboard (sample data you want to work with) go to the top right hand side there where there is a button labeled Share</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Cb1Bw-j3RBsWbgeRRmL6NQ.png" /></figure><p>Give the dashboard a name. Under the Advanced publish option you can select the options that you wish to enable. I have selected all of them to fully test out all functionality.</p><p>Next you will have the option to drill down into who has access to this specific set of data. Because this is a demo environment, and most likely you do not have any other users — you can leave the Share with all users in this account checked. Then click share.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V20HuvXZ4kHc07f3lGvLiQ.png" /></figure><p>Woohoo! A big step is done. Now towards the top of your browser you have your URL bar, and now we need to copy part of the URL. For example, my link looks something like this below (i have modified the numbers slightly for security purposes):</p><pre>https://us-east-1.quicksight.aws.amazon.com/sn/dashboards/69301f52-e492-44fd-69cf-dfd79e622dc6</pre><p>The part that will be relevant for us is the URL code that follows <strong>…/sn/dashboards/{important-set-of-numbers}</strong></p><p>For me, it would be: <strong>92301f69-e492-44fd-69cf-dfd79e6ffdc6</strong> This part of the URL is <strong>STATIC</strong> and will be utilized by our AWS CLI tool on the Wordpress server.</p><p>Now when an external application (node.js, python, php) tries to use this embedded URL, it also requires an additional security key to be attached to this static URL. This security key is generated via an API request to AWS which expires roughly ever 10 minutes (?) to maintain security. Why do I mention this?</p><blockquote>Because having this URL is NOT ENOUGH to get the dashboard embedding to work. You cannot just embed this URL into an iFrame and expect it to work — it will not because it is missing the security key.</blockquote><p>So to make this happen we have to create a few lines of custom PHP code that will allow our Wordpress site to call the AWS Quicksigh API and provide it with some user detail, and then receive the response that will contain our security key to display the Quicksight dashboard. If this doesn’t make sense yet, that is ok. There is some <a href="https://docs.aws.amazon.com/quicksight/latest/user/embedded-dashboards-with-iam-setup-step-3.html">documentation on AWS</a> that walks through this.</p><h3>Part 3: IAM Credentials</h3><p>Log into the AWS management console and navigate to IAM and then Policies.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/836/1*fXt1e2eWWh_oxaUFotQeig.png" /></figure><p>We will want to create a new policy that we can attach to our existing account, (or another account) that grants permissions to 1) get a registered Quicksight user and 2) the embedded dashboard URL. For those following along, this is described in <a href="https://docs.aws.amazon.com/quicksight/latest/user/embedded-dashboards-with-iam-setup-step-2.html">Part 2 of the AWS documentation</a>.</p><p>When you read their documentation you will see something like this:</p><pre>{<br>    &quot;Version&quot;: &quot;2012-10-17&quot;,<br>    &quot;Statement&quot;: [<br>        {<br>            &quot;Action&quot;: &quot;quicksight:RegisterUser&quot;,<br>            &quot;Resource&quot;: &quot;*&quot;,<br>            &quot;Effect&quot;: &quot;Allow&quot;<br>        },<br>        {<br>            &quot;Action&quot;: &quot;quicksight:GetDashboardEmbedUrl&quot;,<br>            &quot;Resource&quot;: &quot;arn:aws:quicksight:us-west-2:11112222333:dashboard/22a7dcbd-7890-6956-9f87-ffd9876ab432&quot;,<br>            &quot;Effect&quot;: &quot;Allow&quot;<br>        }<br>    ]<br>}</pre><p>For the most part, we will be able to copy and paste this all into our new policy with the following exceptions. The parts we will want to change are bolded below:</p><pre>{<br>    &quot;Version&quot;: &quot;2012-10-17&quot;,<br>    &quot;Statement&quot;: [<br>        {<br>            &quot;Action&quot;: &quot;quicksight:RegisterUser&quot;,<br>            &quot;Resource&quot;: &quot;*&quot;,<br>            &quot;Effect&quot;: &quot;Allow&quot;<br>        },<br>        {<br>            &quot;Action&quot;: &quot;quicksight:GetDashboardEmbedUrl&quot;,<br>            &quot;Resource&quot;: &quot;arn:aws:quicksight:<strong>us-west-2:11112222333</strong>:dashboard/<strong>22a7dcbd-7890-6956-9f87-ggd9876ab432</strong>&quot;,<br>            &quot;Effect&quot;: &quot;Allow&quot;<br>        }<br>    ]<br>}</pre><p>The first part is the location and account identification (<strong>us-west-2:11112222333) </strong>and the second part is the static URL of the dashboard that we want to share (<strong>69a7dcbd-7890–6956–9f87-ffd9876ab469)</strong>.</p><p>My dashboard is located in us-east-1 for instance, and my account number is found under users in AWS quicksight. The static URL should be replaced with your own that you previously saved .</p><p>Once you have modified the policy save it. You should then assign this policy to the a user account that you have already created, or create a new user and then assign this policy to them. Be sure that you have that users access key ID (a 20 character key that looks something like AKIZX….LEUUG1) along with a secret access key (a 40 character key that looks something like XLUz….reQjnlAg3FY….NdDsHF).</p><h4>Now on to the final step!</h4><h3>Part 4: Connecting Wordpress with Quicksight</h3><p>Login as admin to your Wordpress site and navigate to our PHP plugin that we installed in Part 1.</p><p>You should see a menu that looks something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8dHXCNvcHIh-zMT3VTM_ww.png" /></figure><p>As you can see I have already created 2 short-codes that contain some PHP that are named <em>dashboard1</em> and <em>dashboard2</em>.</p><p>Click on the button Add New PHP Code Snippet and insert in the following block of code. I have bolded the sections that you will be inserting in your own data:</p><pre>&lt;?php<br>$region=&#39;<strong>YOUR REGION</strong>&#39;;<br>$key=&#39;<strong>YOUR KEY ID</strong>&#39;;<br>$secret= &#39;<strong>YOUR SECRET</strong>&#39;;<br>putenv(&#39;AWS_DEFAULT_REGION=&#39; . $region);<br>putenv(&#39;AWS_ACCESS_KEY_ID=&#39; . $key);<br>putenv(&#39;AWS_SECRET_ACCESS_KEY=&#39; . $secret);<br>$cmd2 = &quot;aws quicksight get-dashboard-embed-url --aws-account-id <strong>YOURACCOUNTID</strong> --dashboard-id <strong>YOURDASHBOARDURL</strong> --identity-type IAM | jq -r &#39;.EmbedUrl&#39;&quot;;<br>$exec2 = shell_exec($cmd2);<br>settype($exec2, &quot;string&quot;);<br>$regions= &#39;&quot;&#39;.$exec2 .&#39;&quot;&#39;;<br>$regions = preg_replace(&#39;/\s+/&#39;, &#39;&#39;, $regions);<br>echo $regions;<br>?&gt;</pre><h3>What does this stuff above do?</h3><p>First it creates three variables that contain the region, key, and secret for our AWS account (lines 2–4). It then utilizes putenv to store these as environmental variables (lines 5–7). Next we create a variable called cmd2 that will store a terminal command that utilizes our AWS CLI tool to request a new security key be generated along with our embedded URL (lines 8–10), and parses the JSON response returned with jq to extract our our new embedded url and security key. Then it runs the terminal command with <em>shell_exec </em>and saves the output in a variable called exec2 (line 11), makes that variable a string (line 12), adds double quotes to it (line 13), and finally removes any white space (line 14)<em>. </em>The last line echo $regions then prints out our final, clean URL with the security code that can now be ingested by an iFrame.</p><p>Now for the bolded sections. Let’s fill in those variables. <em>Below are some examples of</em><strong><em> fake data</em></strong><em> that contain the </em><strong><em>right structure and character count</em>:</strong></p><pre><strong>YOUR REGION</strong>: us-east-1<br><strong>YOUR KEY ID</strong>: AKIAKF9MOV69S9LEVQG9<br><strong>YOUR SECRET</strong>: EHavae9Lf4VNSA1I696w+EInQpAvQr2U5bTf5+Ju<br><strong>YOURACCOUNTID: </strong>351333326999<strong><br>YOURDASHBOARDURL</strong>: 69401f25-e469-4a7f-92gm-dfd69e611dc6</pre><p>So the final version should look something like this:</p><pre>&lt;?php<br>$region=&#39;us-east-1&#39;;<br>$key=&#39;AKIAKF9MOV69S9LEVQG9&#39;;<br>$secret= &#39;EHavae9Lf4VNSA1I696w+EInQpAvQr2U5bTf5+Ju&#39;;<br>putenv(&#39;AWS_DEFAULT_REGION=&#39; . $region);<br>putenv(&#39;AWS_ACCESS_KEY_ID=&#39; . $key);<br>putenv(&#39;AWS_SECRET_ACCESS_KEY=&#39; . $secret);<br>$cmd2 = &quot;aws quicksight get-dashboard-embed-url --aws-account-id 351333326999 --dashboard-id 69401f25-e469-4a7f-92gm-dfd69e611dc6 --identity-type IAM | jq -r &#39;.EmbedUrl&#39;&quot;;<br>$exec2 = shell_exec($cmd2);<br>settype($exec2, &quot;string&quot;);<br>$regions= &#39;&quot;&#39;.$exec2 .&#39;&quot;&#39;;<br>$regions = preg_replace(&#39;/\s+/&#39;, &#39;&#39;, $regions);<br>echo $regions;<br>?&gt;</pre><p>Click save and give it some memorable name like I have, dashboard1 for example. This will then provide you with a short code that can be inserted into a webpage that provides you with your new embedded URL with a security code.</p><p>My short code is [xyz-ips snippet=&quot;dashboard1&#39;]</p><h3><strong>THE FINAL STEP:</strong></h3><p>Now it’s time to create a new blank Wordpress page that we will insert HTML code along with our new PHP short code (that outputs the new embedded URL + security code link) for a iFrame to display.</p><p><strong>Step 1: create a new blank page:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mmomziflO5ZLCzJTXAbG9A.png" /></figure><p><strong>Step 2: Create a new text box. View it in HTML mode and insert in the following code, replacing the bold piece with your own PHP snippet name:</strong></p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>&lt;head&gt;<br>    &lt;title&gt;Basic Embed&lt;/title&gt;<br>    &lt;script type=&quot;text/javascript&quot; src=&quot;<a href="https://unpkg.com/amazon-quicksight-embedding-sdk@1.0.2/dist/quicksight-embedding-js-sdk.min.js">https://unpkg.com/amazon-quicksight-embedding-sdk@1.0.2/dist/quicksight-embedding-js-sdk.min.js</a>&quot;&gt;&lt;/script&gt;<br>    &lt;script type=&quot;text/javascript&quot;&gt;<br>        function embedDashboard() {<br>            var containerDiv = document.getElementById(&quot;dashboardContainer&quot;);<br>            var params = {<br>                url: [xyz-ips snippet=&quot;<strong>dashboard1</strong>&quot;],<br>                container: containerDiv,<br>                height: &quot;1100px&quot;,<br>                width: &quot;1200px&quot;<br>            };<br>            var dashboard = QuickSightEmbedding.embedDashboard(params);<br>            dashboard.on(&#39;error&#39;, function() {});<br>            dashboard.on(&#39;load&#39;, function() {});<br>            dashboard.setParameters({country: &#39;Canada&#39;});<br>        }<br>    &lt;/script&gt;<br>&lt;/head&gt;<br>&lt;body data-rsssl=1 data-rsssl=1 data-rsssl=1 data-rsssl=1 data-rsssl=1 onload=&quot;embedDashboard()&quot;&gt;<br>    &lt;div id=&quot;dashboardContainer&quot;&gt;&lt;/div&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p>What is happening here? We have utilized some of the code provided to us by the <a href="https://docs.aws.amazon.com/quicksight/latest/user/embedded-dashboards-example-html.html">Official AWS documentation</a> for embedding via HTML. You can see that it calls a javascript helper package created by AWS for Quicksight (<a href="https://unpkg.com/amazon-quicksight-embedding-sdk@1.0.2/dist/quicksight-embedding-js-sdk.min.js">https://unpkg.com/amazon-quicksight-embedding-sdk@1.0.2/dist/quicksight-embedding-js-sdk.min.js</a>), and then half way down ingests a variable URL which is provided by our PHP plugin widget.</p><p><strong>Step 3: Click save and exit out of preview mode. Publish the page.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sVxfOICgrMQSJtiOyrQNAg.png" /></figure><p>I used the <a href="https://www.elegantthemes.com/gallery/divi/">DIVI Wordpress theme </a>in my example to do some styling, so it may look different from what you have. But what you should now be looking at is a AWS quicksight dashboard embedded on your own Wordpress page.</p><h3>Thanks for reading!</h3><p>If you have questions shoot me a message and follow me on Linkedin: <a href="https://www.linkedin.com/in/hantswilliams/">https://www.linkedin.com/in/hantswilliams/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4f5793469123" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/sharable-data-informatics-aws-quicksight-with-wordpress-4f5793469123">Sharable Data Informatics: AWS Quicksight with Wordpress</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>