Visualize Amazon S3 knowledge utilizing Amazon Athena and Amazon Managed Grafana


    Grafana is a well-liked open-source analytics platform which you could make use of to create, discover, and share your knowledge via versatile dashboards. Its use instances embrace utility and IoT machine monitoring, and visualization of operational and enterprise knowledge, amongst others. You possibly can create your dashboard with your individual datasets or publicly accessible datasets associated to your trade.

    In November 2021, the AWS workforce along with Grafana Labs introduced the Amazon Athena knowledge supply plugin for Grafana. The characteristic permits you to visualize info on a Grafana dashboard utilizing knowledge saved in Amazon Easy Storage Service (Amazon S3) buckets, with assist from Amazon Athena, a serverless interactive question service. As well as, you possibly can provision Grafana dashboards utilizing Amazon Managed Grafana, a totally managed service for open-source Grafana and Enterprise Grafana.

    On this put up, we present how one can create and configure a dashboard in Amazon Managed Grafana that queries knowledge saved on Amazon S3 utilizing Athena.

    Answer overview

    The next diagram is the structure of the answer.

    Architecture diagram

    The answer is comprised of a Grafana dashboard, created in Amazon Managed Grafana, populated with knowledge queried utilizing Athena. Athena runs queries in opposition to knowledge saved in Amazon S3 utilizing commonplace SQL. Athena integrates with the AWS Glue Knowledge Catalog, a metadata retailer for knowledge in Amazon S3, which incorporates info such because the desk schema.

    To implement this answer, you full the next high-level steps:

    1. Create and configure an Athena workgroup.
    2. Configure the dataset in Athena.
    3. Create and configure a Grafana workspace.
    4. Create a Grafana dashboard.

    Create and configure an Athena workgroup

    By default, the AWS Id and Entry Administration (IAM) function utilized by Amazon Managed Grafana has the AmazonGrafanaAthenaAccess IAM coverage hooked up. This coverage provides the Grafana workspace entry to question all Athena databases and tables. Extra importantly, it provides the service entry to learn knowledge written to S3 buckets with the prefix grafana-athena-query-results-. To ensure that Grafana to have the ability to learn the Athena question outcomes, you’ve got two choices:

    On this put up, we go along with the primary choice. To do this, full the next steps:

    1. Create an S3 bucket named grafana-athena-query-results-<identify>. Change <identify> with a singular identify of your selection.
    2. On the Athena console, select Workgroups within the navigation pane.
    3. Select Create workgroup.
    4. Beneath Workgroup identify, enter a singular identify of your selection.
    5. For Question consequence configuration, select Browse S3.
    6. Choose the bucket you created and select Select.
    7. For Tags, select Add new tag.
    8. Add a tag with the important thing GrafanaDataSource and the worth true.
    9. Select Create workgroup.

    It’s vital that you just add the tag described in steps 7–8. If the tag isn’t current, the workgroup received’t be accessible by Amazon Managed Grafana.

    For extra details about the Athena question outcomes location, confer with Working with question outcomes, current queries, and output information.

    Configure the dataset in Athena

    For this put up, we use the NOAA World Historic Climatology Community Day by day (GHCN-D) dataset, from the Nationwide Oceanic and Atmospheric Administration (NOAA) company. The dataset is offered within the Registry of Open Knowledge on AWS, a registry that exists to assist folks uncover and share datasets.

    The GHCN-D dataset incorporates meteorological parts similar to day by day most and minimal temperatures. It’s a composite of local weather data from quite a few places—some places include greater than 175 years recorded.

    The GHCN-D knowledge is in CSV format and is saved in a public S3 bucket (s3://noaa-ghcn-pds/). You entry the information via Athena. To start out utilizing Athena, you could create a database:

    1. On the Athena console, select Question editor within the navigation pane.
    2. Select the workgroup, created within the earlier step, on the highest proper menu.
    3. To create a database named mydatabase, enter the next assertion:
    CREATE DATABASE mydatabase

    1. Select Run.
    2. From the Database record on the left, select mydatabase to make it your present database.

    Now that you’ve got a database, you possibly can create a desk within the AWS Glue Knowledge Catalog to start out querying the GHCN-D dataset.

    1. Within the Athena question editor, run the next question:
    CREATE EXTERNAL TABLE `noaa_ghcn_pds`(
      `id` string, 
      `year_date` string, 
      `aspect` string, 
      `data_value` string, 
      `m_flag` string, 
      `q_flag` string, 
      `s_flag` string, 
      `obs_time` string
    WITH SERDEPROPERTIES ('separatorChar'=',')
    STORED AS INPUTFORMAT 'org.apache.hadoop.mapred.TextInputFormat' 
    LOCATION 's3://noaa-ghcn-pds/csv/'
    TBLPROPERTIES ('classification'='csv')

    After that, the desk noaa_ghcn_pds ought to seem underneath the record of tables to your database. Within the previous assertion, we outline columns based mostly on the GHCN-D knowledge construction. For a full description of the variables and knowledge construction, confer with the dataset’s readme file.

    With the database and the desk configured, you can begin operating SQL queries in opposition to all the dataset. For the aim of this put up, you create a second desk containing a subset of the information: the utmost temperatures of 1 climate station situated in Retiro Park (or just El Retiro), one of many largest parks of the town of Madrid, Spain. The identification of the station is SP000003195 and the aspect of curiosity is TMAX.

    1. Run the next assertion on the Athena console to create the second desk:
    CREATE TABLE madrid_tmax WITH (format="PARQUET") AS
    SELECT CAST(data_value AS actual) / 10 AS t_max,
        SUBSTR(year_date, 1, 4) || '-' || SUBSTR(year_date, 5, 2) || '-' || SUBSTR(year_date, 7, 2) AS date
      ) AS iso_date
    FROM "noaa_ghcn_pds"
    WHERE id = 'SP000003195'
      AND aspect="TMAX"

    After that, the desk madrid_tmax ought to seem underneath the record of tables to your database. Word that within the previous assertion, the temperature worth is split by 10. That’s as a result of temperatures are initially recorded in tenths of Celsius levels. We additionally alter the date format. Each changes make the consumption of the information simpler.

    Not like the noaa_ghcn_pds desk, the madrid_tmax desk isn’t linked with the unique dataset. Meaning its knowledge received’t mirror updates made to the GHCN-D dataset. As an alternative, it holds a snapshot of the second of its creation. That is probably not very best in sure eventualities, however is appropriate right here.

    Create and configure a Grafana workspace

    The following step is to provision and configure a Grafana workspace and assign a consumer to the workspace.

    Create your workspace

    On this put up, we use the AWS Single Signal-On (AWS SSO) choice to arrange the customers. You possibly can skip this step if you have already got a Grafana workspace.

    1. On the Amazon Managed Grafana console, select Create Workspace.
    2. Give your workspace a reputation, and optionally an outline.
    3. Select Subsequent.
    4. Choose AWS IAM Id Middle (successor to AWS SSO).
    5. For Permission sort, select Service Managed and select Subsequent.
    6. For Account entry, choose Present account.
    7. For Knowledge sources, choose Amazon Athena and select Subsequent.
    8. Overview the small print and select Create workspace.

    This begins the creation of the Grafana workspace.

    Create a consumer and assign it to the workspace

    The final step of the configuration is to create a consumer to entry the Grafana dashboard. Full the next steps:

    1. Create a consumer to your AWS SSO id retailer in the event you don’t have one already.
    2. On the Amazon Managed Grafana console, select All workspaces within the navigation pane.
    3. Select your Grafana workspace to open the workspace particulars.
    4. On the Authentication tab, select Assign new consumer or group.
    5. Choose the consumer you created and select Assign customers and teams.
    6. Change the consumer sort by choosing the consumer and on the Motion menu, select Make admin.

    Create a Grafana dashboard

    Now that you’ve got Athena and Amazon Managed Grafana configured, create a Grafana dashboard with knowledge fetched from Amazon S3 utilizing Athena. Full the next steps:

    1. On the Amazon Managed Grafana console, select All workspaces within the navigation pane.
    2. Select the Grafana workspace URL hyperlink.
    3. Log in with the consumer you assigned within the earlier step.
    4. Within the navigation pane, select the decrease AWS icon (there are two) after which select Athena on the AWS providers tab.
    5. Select the Area, database, and workgroup used beforehand, then select Add 1 knowledge supply.
    6. Beneath Provisioned knowledge sources, select Go to settings on the newly created knowledge supply.
    7. Choose Default after which select Save & check.
    8. Within the navigation pane, hover over the plus signal after which select Dashboard to create a brand new dashboard.
    9. Select Add a brand new panel.
    10. Within the question pane, enter the next question:
    choose iso_date as time, t_max from madrid_tmax the place $__dateFilter(iso_date) order by iso_date

    1. Select Apply.
    2. Change the time vary on the highest proper nook.

    For instance, in the event you change to Final 2 years, you need to see one thing just like the next screenshot.

    Temperature visualization

    Now that you just’re capable of populate your Grafana dashboard with knowledge fetched from Amazon S3 utilizing Athena, you possibly can experiment with totally different visualizations and configurations. Grafana offers a lot of choices, and you may alter your dashboard to your preferences, as proven within the following instance screenshot of day by day most temperatures.

    As you possibly can see on this visualization, Madrid can get actually scorching on the summer season!

    For extra info on how one can customise Grafana visualizations, confer with Visualization panels.

    Clear up

    Should you adopted the directions on this put up in your individual AWS account, don’t overlook to wash up the created assets to keep away from additional expenses.


    On this put up, you realized how one can use Amazon Managed Grafana together with Athena to question knowledge saved in an S3 bucket. For instance, we used a subset of the GHCN-D dataset, accessible within the Registry of Open Knowledge on AWS.

    Take a look at Amazon Managed Grafana and begin creating different dashboards utilizing your individual knowledge or different publicly accessible datasets saved in Amazon S3.

    Concerning the authors

    Pedro Pimentel is a Prototyping Architect engaged on the AWS Cloud Engineering and Prototyping workforce, based mostly in Brazil. He works with AWS clients to innovate utilizing new applied sciences and providers. In his spare time, Pedro enjoys touring and biking.

    Rafael Werneck is a Senior Prototyping Architect at AWS Cloud Engineering and Prototyping, based mostly in Brazil. Beforehand, he labored as a Software program Improvement Engineer on and Amazon RDS Efficiency Insights.


    Please enter your comment!
    Please enter your name here