Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
console.log(`${url}: Processing`);
// Fetch the contents at the URL
console.log(`${url}: Getting`);
try {
const res = await fetch.default(url);
} catch (err) {
console.log(`${url}: Failed to GET`);
return;
}
}
});
let alarmIndex = 0;
const funcMetric = awsx.lambda.metrics.duration({ function: subscription.func, unit: "Seconds" });
const funcAlarm = funcMetric.createAlarm("alarm" + alarmIndex++, { threshold: 120, evaluationPeriods: 2 });
const topicMetric = awsx.sns.metrics.numberOfMessagesPublished({ topic });
const topicAlarm = topicMetric.createAlarm("alarm" + alarmIndex++, { threshold: 1000, evaluationPeriods: 2 });
const queue = new aws.sqs.Queue("terraform_queue", {
delaySeconds: 90,
maxMessageSize: 2048,
messageRetentionSeconds: 86400,
receiveWaitTimeSeconds: 10,
tags: {
Environment: "production",
},
});
const queueMetric = awsx.sqs.metrics.sentMessageSize({ queue });
console.log(`${url}: Processing`);
// Fetch the contents at the URL
console.log(`${url}: Getting`);
try {
const res = await fetch.default(url);
} catch (err) {
console.log(`${url}: Failed to GET`);
return;
}
}
});
// Get the metric for the lambda that processing our topic requests.
const funcMetric = awsx.lambda.metrics.duration({ function: subscription.func });
// Create an alarm if this lambda takes more than 1000ms to complete in a period of 10 minutes over
// at least five periods in a row.
const funcAlarm1 = funcMetric.with({ unit: "Milliseconds", period: 600 })
.createAlarm("SlowUrlProcessing", { threshold: 1000, evaluationPeriods: 5 });
// Also create a dashboard to track this.
const dashboard = new awsx.cloudwatch.Dashboard("TopicData", {
widgets: [
new awsx.cloudwatch.SingleNumberMetricWidget({
title: "Requests in the last minute",
width: 10,
metrics: awsx.lambda.metrics.invocations({
function: subscription.func,
statistic: "Sum",
period: 60,
// Get the metric for the lambda that processing our topic requests.
const funcMetric = awsx.lambda.metrics.duration({ function: subscription.func });
// Create an alarm if this lambda takes more than 1000ms to complete in a period of 10 minutes over
// at least five periods in a row.
const funcAlarm1 = funcMetric.with({ unit: "Milliseconds", period: 600 })
.createAlarm("SlowUrlProcessing", { threshold: 1000, evaluationPeriods: 5 });
// Also create a dashboard to track this.
const dashboard = new awsx.cloudwatch.Dashboard("TopicData", {
widgets: [
new awsx.cloudwatch.SingleNumberMetricWidget({
title: "Requests in the last minute",
width: 10,
metrics: awsx.lambda.metrics.invocations({
function: subscription.func,
statistic: "Sum",
period: 60,
}),
}),
new awsx.cloudwatch.LineGraphMetricWidget({
title: "Lambda duration",
width: 14,
// Place a line on the graph to indicate where our alarm will be triggered.
annotations: new awsx.cloudwatch.HorizontalAnnotation(funcAlarm1),
// Log our different p90/p95/p99 latencies
metrics: [
funcMetric.with({ extendedStatistic: 90, label: "Duration p90" }),
funcMetric.with({ extendedStatistic: 95, label: "Duration p95" }),