Skip to content

AWS.AMP reference

Source: src/AWS/AMP/AlertManagerDefinition.ts

The Alertmanager definition for an Amazon Managed Service for Prometheus workspace — configures how firing alerts are grouped, routed, and dispatched to receivers (SNS, etc.). A workspace has at most one.

AlertManagerDefinition: Creating an Alert Manager Definition

Section titled “AlertManagerDefinition: Creating an Alert Manager Definition”
const workspace = yield* AMP.Workspace("Metrics", {});
const alerts = yield* AMP.AlertManagerDefinition("Alerts", {
workspaceId: workspace.workspaceId,
definition: `alertmanager_config: |
route:
receiver: default
receivers:
- name: default`,
});

Source: src/AWS/AMP/AnomalyDetector.ts

A Random Cut Forest anomaly detector inside an Amazon Managed Service for Prometheus workspace — continuously evaluates a PromQL query and emits anomaly scores as new metrics in the same workspace.

AnomalyDetector: Creating an Anomaly Detector

Section titled “AnomalyDetector: Creating an Anomaly Detector”
const workspace = yield* AMP.Workspace("Metrics", {});
const detector = yield* AMP.AnomalyDetector("RequestSpikes", {
workspaceId: workspace.workspaceId,
alias: "request-spikes",
query: 'rate(http_requests_total{job="api"}[5m])',
evaluationInterval: "1 minute",
missingDataAction: { skip: true },
});

Source: src/AWS/AMP/DescribeWorkspace.ts

Runtime binding for aps:DescribeWorkspace.

Bind this operation to a Workspace inside a function runtime to get a callable that reads the workspace’s control-plane metadata (status, alias, endpoint). Provide the DescribeWorkspaceHttp layer on the Function to satisfy the binding.

const describeWorkspace = yield* AMP.DescribeWorkspace(workspace);
const response = yield* describeWorkspace();
const status = response.workspace.status.statusCode;

Source: src/AWS/AMP/GetDefaultScraperConfiguration.ts

Runtime binding for aps:GetDefaultScraperConfiguration.

An account-level binding — call it with no arguments to get a callable that returns the AWS-managed default scraper configuration as Prometheus scrape-configuration YAML text (decoded from the wire blob). Provide the GetDefaultScraperConfigurationHttp layer on the Function to satisfy the binding.

GetDefaultScraperConfiguration: Scraper Configuration

Section titled “GetDefaultScraperConfiguration: Scraper Configuration”
const getDefaultScraperConfiguration =
yield* AMP.GetDefaultScraperConfiguration();
const yaml = yield* getDefaultScraperConfiguration();

Source: src/AWS/AMP/GetLabels.ts

Runtime binding for aps:GetLabels — list label names and label values from an AMP Workspace’s Prometheus-compatible query API, SigV4-signed with the host Function’s credentials.

List Label Names

const labels = yield* AMP.GetLabels(workspace);
const names = yield* labels.labelNames();

List Metric Names

const metricNames = yield* labels.labelValues({ label: "__name__" });

Source: src/AWS/AMP/GetMetricMetadata.ts

Runtime binding for aps:GetMetricMetadata — read metric metadata (type, help, unit) from an AMP Workspace’s Prometheus-compatible api/v1/metadata endpoint, SigV4-signed with the host Function’s credentials.

GetMetricMetadata: Reading Metric Metadata

Section titled “GetMetricMetadata: Reading Metric Metadata”
const getMetricMetadata = yield* AMP.GetMetricMetadata(workspace);
const metadata = yield* getMetricMetadata({});
// { http_requests_total: [{ type: "counter", help: "...", unit: "" }], ... }

Source: src/AWS/AMP/GetSeries.ts

Runtime binding for aps:GetSeries — find series (full label sets) that match a selector via an AMP Workspace’s Prometheus-compatible api/v1/series endpoint, SigV4-signed with the host Function’s credentials.

const getSeries = yield* AMP.GetSeries(workspace);
const series = yield* getSeries({ match: ['{__name__="up"}'] });
// [{ __name__: "up", job: "api", instance: "..." }, ...]

Source: src/AWS/AMP/ListWorkspaces.ts

Runtime binding for aps:ListWorkspaces.

An account-level binding — call it with no arguments to get a callable that lists AMP workspaces in the region. Provide the ListWorkspacesHttp layer on the Function to satisfy the binding.

const listWorkspaces = yield* AMP.ListWorkspaces();
const response = yield* listWorkspaces();
const ids = response.workspaces.map((workspace) => workspace.workspaceId);

Source: src/AWS/AMP/LoggingConfiguration.ts

The rules/alerting logging configuration of an Amazon Managed Service for Prometheus workspace — ships rule evaluation failures and Alertmanager delivery errors to a CloudWatch Logs log group. A workspace has at most one.

LoggingConfiguration: Creating a Logging Configuration

Section titled “LoggingConfiguration: Creating a Logging Configuration”
const workspace = yield* AMP.Workspace("Metrics", {});
const logs = yield* Logs.LogGroup("AmpLogs", {
logGroupName: "/aws/vendedlogs/prometheus/metrics",
});
const logging = yield* AMP.LoggingConfiguration("Logging", {
workspaceId: workspace.workspaceId,
logGroupArn: logs.logGroupArn,
});

Source: src/AWS/AMP/QueryLoggingConfiguration.ts

The query logging configuration of an Amazon Managed Service for Prometheus workspace — ships PromQL query logs (query text, QSP cost, response code) to CloudWatch Logs. A workspace has at most one.

QueryLoggingConfiguration: Creating a Query Logging Configuration

Section titled “QueryLoggingConfiguration: Creating a Query Logging Configuration”
const workspace = yield* AMP.Workspace("Metrics", {});
const logs = yield* Logs.LogGroup("QueryLogs", {
logGroupName: "/aws/vendedlogs/prometheus/metrics-queries",
});
const queryLogging = yield* AMP.QueryLoggingConfiguration("QueryLogging", {
workspaceId: workspace.workspaceId,
destinations: [{ logGroupArn: logs.logGroupArn, qspThreshold: 1000 }],
});

Source: src/AWS/AMP/QueryMetrics.ts

Runtime binding for aps:QueryMetrics — evaluate PromQL against an AMP Workspace’s Prometheus-compatible query API (api/v1/query and api/v1/query_range), SigV4-signed with the host Function’s credentials.

Instant Query

const metrics = yield* AMP.QueryMetrics(workspace);
const result = yield* metrics.query({ query: "up" });
if (result.resultType === "vector") {
for (const sample of result.result) {
console.log(sample.metric.__name__, sample.value[1]);
}
}

Range Query

const result = yield* metrics.queryRange({
query: "rate(http_requests_total[5m])",
start: new Date(Date.now() - 3_600_000),
end: new Date(),
step: "30 seconds",
});

Source: src/AWS/AMP/RemoteWrite.ts

Runtime binding for aps:RemoteWrite — push metric samples into an AMP Workspace via its Prometheus remote-write endpoint (api/v1/remote_write), SigV4-signed with the host Function’s credentials.

The protobuf + snappy remote-write body is encoded internally — callers pass plain metric names, labels, and samples.

Push a Counter Sample

const remoteWrite = yield* AMP.RemoteWrite(workspace);
yield* remoteWrite({
timeseries: [{
name: "jobs_processed_total",
labels: { queue: "default" },
samples: [{ value: 42 }],
}],
});

Backfill Samples with Explicit Timestamps

yield* remoteWrite({
timeseries: [{
name: "temperature_celsius",
labels: { sensor: "a1" },
samples: [
{ value: 20.1, timestamp: Date.now() - 60_000 },
{ value: 20.4, timestamp: Date.now() },
],
}],
});

Source: src/AWS/AMP/ResourcePolicy.ts

The resource-based policy of an Amazon Managed Service for Prometheus workspace — grants cross-account or fine-grained same-account access to the workspace’s data plane (remote-write, query). A workspace has at most one.

ResourcePolicy: Creating a Resource Policy

Section titled “ResourcePolicy: Creating a Resource Policy”
const workspace = yield* AMP.Workspace("Metrics", {});
const policy = yield* AMP.ResourcePolicy("Sharing", {
workspaceId: workspace.workspaceId,
policyDocument: JSON.stringify({
Version: "2012-10-17",
Statement: [
{
Effect: "Allow",
Principal: { AWS: "arn:aws:iam::123456789012:root" },
Action: ["aps:QueryMetrics"],
Resource: workspace.workspaceArn,
},
],
}),
});

Source: src/AWS/AMP/RuleGroupsNamespace.ts

A rule groups namespace inside an Amazon Managed Service for Prometheus workspace — a container of Prometheus recording and alerting rules, supplied as a YAML definition.

RuleGroupsNamespace: Creating a Rule Groups Namespace

Section titled “RuleGroupsNamespace: Creating a Rule Groups Namespace”
const workspace = yield* AMP.Workspace("Metrics", {});
const rules = yield* AMP.RuleGroupsNamespace("Rules", {
workspaceId: workspace.workspaceId,
name: "default",
definition: `groups:
- name: example
rules:
- record: metric:requests:rate5m
expr: rate(http_requests_total[5m])`,
});

Source: src/AWS/AMP/Scraper.ts

An Amazon Managed Service for Prometheus scraper — a fully-managed, agentless collector that pulls metrics from an Amazon EKS cluster (or a VPC-based Prometheus-compatible source) and remote-writes them into an AMP workspace.

Scraper provisioning is slow (the service creates network interfaces and an IAM role; expect several minutes to reach ACTIVE).

Scrape an EKS Cluster into a Workspace

const workspace = yield* AMP.Workspace("Metrics", {});
const scraper = yield* AMP.Scraper("ClusterScraper", {
alias: "eks-metrics",
scrapeConfiguration: defaultScrapeConfigYaml,
source: {
eksConfiguration: {
clusterArn: cluster.clusterArn,
subnetIds: [subnetA.subnetId, subnetB.subnetId],
},
},
destinationWorkspaceArn: workspace.workspaceArn,
});

Scrape a VPC-Based Source

const scraper = yield* AMP.Scraper("VpcScraper", {
scrapeConfiguration: scrapeConfigYaml,
source: {
vpcConfiguration: {
subnetIds: [subnet.subnetId],
securityGroupIds: [securityGroup.securityGroupId],
},
},
destinationWorkspaceArn: workspace.workspaceArn,
});

Source: src/AWS/AMP/ScraperLoggingConfiguration.ts

The logging configuration of an Amazon Managed Service for Prometheus scraper — ships the scraper’s component logs (service discovery, collection, export) to a CloudWatch Logs log group. A scraper has at most one.

ScraperLoggingConfiguration: Creating a Scraper Logging Configuration

Section titled “ScraperLoggingConfiguration: Creating a Scraper Logging Configuration”
const logs = yield* Logs.LogGroup("ScraperLogs", {
logGroupName: "/aws/vendedlogs/prometheus/scraper",
});
const logging = yield* AMP.ScraperLoggingConfiguration("ScraperLogging", {
scraperId: scraper.scraperId,
logGroupArn: logs.logGroupArn,
});

Source: src/AWS/AMP/Workspace.ts

An Amazon Managed Service for Prometheus (AMP) workspace — a logical, fully-managed Prometheus-compatible metrics store. Metrics are ingested via remote-write and queried through the workspace’s Prometheus-compatible endpoint.

Basic Workspace

const workspace = yield* AMP.Workspace("Metrics", {
alias: "production-metrics",
});

Workspace with Customer-Managed Encryption

const workspace = yield* AMP.Workspace("Metrics", {
alias: "production-metrics",
kmsKeyArn: key.keyArn,
tags: { team: "observability" },
});

Workspace with Custom Retention and Series Limits

const workspace = yield* AMP.Workspace("Metrics", {
alias: "production-metrics",
retentionPeriod: "30 days",
limitsPerLabelSet: [
{ labelSet: { team: "billing" }, maxSeries: 100_000 },
{ labelSet: {}, maxSeries: 1_000_000 }, // default bucket
],
});
// prometheusEndpoint ends in a trailing slash; append `api/v1/remote_write`
const remoteWrite = `${workspace.prometheusEndpoint}api/v1/remote_write`;
// inside a Lambda Function's effect (provide the *Http layers):
const remoteWrite = yield* AMP.RemoteWrite(workspace);
const metrics = yield* AMP.QueryMetrics(workspace);
yield* remoteWrite({
timeseries: [{ name: "jobs_done_total", samples: [{ value: 1 }] }],
});
const result = yield* metrics.query({ query: "jobs_done_total" });