Creating a workspace in Amazon Managed Service for Prometheus – Enabling the Observability of Your Workloads

Mike Naughton | October 12th, 2022


Amazon Managed Service for Prometheus is a serverless Prometheus-compatible service that is highly resilient and scales automatically to changing storage or performance needs. It is well integrated with AWS’s container ecosystem.

For our use case, we need a workspace that offers dedicated storage and querying capability for Prometheus metrics. At the time of writing, there are no L2-level or L3-level CDK constructs available for the service, so we will use an L1 CloudFormation construct in our CDK stack:

…import { aws_aps as aps } from ‘aws-cdk-lib’;……const apsWorkspace = new aps.CfnWorkspace(this, ‘APSWorkspace’, {alias: ‘aws-devops-simplified-aps-workspace’});

The CloudFormation resource simply creates a Prometheus workspace for us, but we still need something that publishes the relevant metrics into this workspace. Let’s cover this next.

Injecting a sidecar OpenTelemetry container in the ECS task definition

With Prometheus created, we can now add a sidecar container to the same ECS task definition that hosts our Flask application and MongoDB database containers. This will allow the OTEL collector to scrape metrics from our application and push them over to the managed Prometheus workspace that we created in the previous section:

As you can see, we are referencing the workspace endpoint in the apsWorkspace CDK resource and passing it further, as the value of the AWS_PROMETHEUS_ENDPOINT environment variable, into the OTEL container. With this, the OTEL collector knows where to push the collected metrics to. Secondly, we define AWS_PROMETHEUS_SCRAPING_ENDPOINT, which tells the collector where to scrape the metrics from. All these configurations are governed by the type of config file that we are using for the OTEL collector. The AWS OTEL collector supports several platforms where it can consume data from or send data to. In our case, we are mostly interested in Prometheus metrics, so we used the /etc/ecs/ecs-amp-prometheus.yaml file from the OTEL Docker container.

Note If you are interested in exploring the contents of this file and all the configuration options it offers, you can go to this link: https://github.com/aws-observability/aws-otel-collector/blob/main/config/ecs/ecs-amp-prometheus.yaml.

Having made all the required code changes for the application and infrastructure, we can now proceed to the most exciting part – deploying the solution in our AWS account.

Leave a Reply

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