Visualize Amazon S3 information utilizing Amazon Athena and Amazon Managed Grafana


Grafana is a well-liked open-source analytics platform you can make use of to create, discover, and share your information by way of versatile dashboards. Its use circumstances embrace utility and IoT system monitoring, and visualization of operational and enterprise information, amongst others. You possibly can create your dashboard with your personal datasets or publicly accessible datasets associated to your trade.

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

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

Resolution 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 information queried utilizing Athena. Athena runs queries in opposition to information saved in Amazon S3 utilizing normal SQL. Athena integrates with the AWS Glue Knowledge Catalog, a metadata retailer for information 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 information 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 two choices:

On this submit, we go together with the primary choice. To try this, full the next steps:

  1. Create an S3 bucket named grafana-athena-query-results-<identify>. Substitute <identify> with a singular identify of your alternative.
  2. On the Athena console, select Workgroups within the navigation pane.
  3. Select Create workgroup.
  4. Underneath Workgroup identify, enter a singular identify of your alternative.
  5. For Question end result 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 simply 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, consult with Working with question outcomes, current queries, and output recordsdata.

Configure the dataset in Athena

For this submit, we use the NOAA International 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 individuals uncover and share datasets.

The GHCN-D dataset comprises meteorological components equivalent to every day most and minimal temperatures. It’s a composite of local weather information from quite a few places—some places comprise greater than 175 years recorded.

The GHCN-D information is in CSV format and is saved in a public S3 bucket (s3://noaa-ghcn-pds/). You entry the information by way of Athena. To begin utilizing Athena, you should 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:

  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 may 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, 
  `component` 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 below the record of tables to your database. Within the previous assertion, we outline columns based mostly on the GHCN-D information construction. For a full description of the variables and information construction, consult with the dataset’s readme file.

With the database and the desk configured, you can begin working SQL queries in opposition to the whole dataset. For the aim of this submit, 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 town of Madrid, Spain. The identification of the station is SP000003195 and the component 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 component="TMAX"

After that, the desk madrid_tmax ought to seem below the record of tables to your database. Observe 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 regulate the date format. Each changes make the consumption of the information simpler.

In contrast to the noaa_ghcn_pds desk, the madrid_tmax desk isn’t linked with the unique dataset. Meaning its information received’t mirror updates made to the GHCN-D dataset. As an alternative, it holds a snapshot of the second of its creation. That will not be ultimate in sure situations, however is appropriate right here.

Create and configure a Grafana workspace

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

Create your workspace

On this submit, 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 kind, 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 main points 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 identification retailer when 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 kind by deciding on 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 information 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 companies tab.
  5. Select the Area, database, and workgroup used beforehand, then select Add 1 information supply.
  6. Underneath Provisioned information sources, select Go to settings on the newly created information supply.
  7. Choose Default after which select Save & take a look at.
  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, when you change to Final 2 years, it is best to see one thing much like the next screenshot.

Temperature visualization

Now that you simply’re in a position to populate your Grafana dashboard with information fetched from Amazon S3 utilizing Athena, you may experiment with completely different visualizations and configurations. Grafana gives plenty of choices, and you may regulate your dashboard to your preferences, as proven within the following instance screenshot of every day most temperatures.

As you may see on this visualization, Madrid can get actually scorching on the summer time!

For extra info on methods to customise Grafana visualizations, consult with Visualization panels.

Clear up

If you happen to adopted the directions on this submit in your personal AWS account, don’t overlook to scrub up the created assets to keep away from additional prices.


On this submit, you discovered methods to use Amazon Managed Grafana along with Athena to question information saved in an S3 bucket. For example, we used a subset of the GHCN-D dataset, accessible within the Registry of Open Knowledge on AWS.

Try Amazon Managed Grafana and begin creating different dashboards utilizing your personal information or different publicly accessible datasets saved in Amazon S3.

In regards to 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 prospects to innovate utilizing new applied sciences and companies. 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.


Leave a Reply

Your email address will not be published. Required fields are marked *