CloudWatch Synthetics
API Blueprint
1. Objective ▾
API Synthetics can monitor any API and validate functionality.
This synthetic polls the Alpha Vantage service and retrieves daily AMZN stock price details over the last 30 days via the TIME_SERIES_DAILY API. A successful response includes a HTTP 200 OK and the target stock symbol.
2. Configuration ▸
JavaScript
var synthetics = require('Synthetics');
const log = require('SyntheticsLogger');
/**
* API canary: alpha_vantage_daily
*
* Validates that the Alpha Vantage public API returns the expected daily
* time-series JSON for AMZN. Runs on the Puppeteer runtime
* (syn-nodejs-puppeteer-18.0), but performs no browser work — it uses the
* Synthetics module's executeHttpStep to issue a GET and assert on the
* response. There is no separate "api" runtime; executeHttpStep works under
* the Puppeteer runtime.
*
* The API key is read from the ALPHA_VANTAGE_API_KEY environment variable
* (wired from the ApiKey CloudFormation parameter) rather than hardcoded, and
* the request URL is built from a base URL plus that key.
*
* Validation rules (the step fails if any is not met):
* - HTTP status is 200.
* - The response body parses as JSON.
* - The parsed object contains a non-empty 'Time Series (Daily)' key.
*
* Alpha Vantage sometimes returns HTTP 200 with a payload like
* {"Note": "...rate limit..."} or {"Information": "..."} instead of the
* time series. Those responses are treated as a failure with a clear log
* message, because the absence of 'Time Series (Daily)' means the canary did
* not get the data it is meant to validate.
*
* Response capture: a stepConfig is passed to executeHttpStep to record the
* response headers and body (and the empty request body) into the canary run
* report / the console's HTTP-steps view. Request headers are NOT included:
* the Alpha Vantage API key is passed in the query string, not in a header, so
* there is nothing security-relevant in the request headers worth capturing.
* The apikey query-string value is masked in the recorded request URL. The
* response body is also written to CloudWatch Logs via log.info.
*/
// Host and path for the Alpha Vantage daily time-series request. The API key is
// appended to the query string at runtime from the environment variable.
const API_HOSTNAME = 'www.alphavantage.co';
const API_PATH_BASE =
'/query?function=TIME_SERIES_DAILY&symbol=AMZN&apikey=';
const apiCanary = async function () {
const apiKey = process.env.ALPHA_VANTAGE_API_KEY;
if (!apiKey) {
log.error('ALPHA_VANTAGE_API_KEY environment variable is not set.');
throw new Error('Missing ALPHA_VANTAGE_API_KEY environment variable.');
}
// Configure response capture GLOBALLY via SyntheticsConfiguration. Verified
// empirically against this runtime (syn-nodejs-puppeteer-18.0): the response
// headers/body capture flags only take effect when set on the global config
// here — passing them solely as a per-step stepConfig left the run report
// showing "Not enabled". restrictedUrlParameters (the URL sanitizer, which
// masks the apikey query parameter in reports/HAR/logs) is likewise a global
// option. Both are confirmed present in the run's effective configuration.
//
// includeRequestHeaders is intentionally left false: the Alpha Vantage API
// key is passed in the query string, not a request header, so request headers
// carry nothing worth capturing.
synthetics.getConfiguration().setConfig({
includeRequestHeaders: false,
includeResponseHeaders: true,
includeRequestBody: true,
includeResponseBody: true,
restrictedUrlParameters: ['apikey'],
});
// executeHttpStep expects an http.request-style options object (hostname,
// path, port, protocol) or a plain URL string — NOT a { url: ... } key. A
// { url } object has no hostname, so the runtime falls back to
// localhost:80 and the request fails with ECONNREFUSED. Use the explicit
// hostname/path/port/protocol form so headers can be supplied too.
const requestOptions = {
hostname: API_HOSTNAME,
method: 'GET',
path: API_PATH_BASE + encodeURIComponent(apiKey),
port: 443,
protocol: 'https:',
headers: {
'User-Agent': 'CloudWatchSynthetics-alpha_vantage_daily',
},
};
// Custom validation callback. By default executeHttpStep only checks that the
// status is 2xx; validating the body requires reading the response stream and
// asserting on the parsed JSON here.
const validateResponse = async function (res) {
return new Promise((resolve, reject) => {
if (res.statusCode !== 200) {
reject(
new Error(
'Expected HTTP 200 from Alpha Vantage but received ' +
res.statusCode +
'.'
)
);
return;
}
let body = '';
res.on('data', (chunk) => {
body += chunk;
});
res.on('end', () => {
// Log the raw response body to CloudWatch Logs. This runs before the
// JSON-parse/validation branches so the payload is captured even for
// rate-limited or malformed responses, which aids diagnosis.
log.info('Alpha Vantage response body: ' + body);
let parsed;
try {
parsed = JSON.parse(body);
} catch (e) {
reject(
new Error(
'Alpha Vantage response was not valid JSON: ' + e.message
)
);
return;
}
const timeSeries = parsed['Time Series (Daily)'];
if (!timeSeries || Object.keys(timeSeries).length === 0) {
// Surface the throttling/informational message Alpha Vantage returns
// with a 200 so the failure is diagnosable from the logs.
const notice =
parsed['Note'] ||
parsed['Information'] ||
parsed['Error Message'] ||
'no "Time Series (Daily)" key in the response';
log.error(
'Alpha Vantage did not return daily time-series data: ' + notice
);
reject(
new Error(
'Validation failed: expected a non-empty "Time Series (Daily)" ' +
'key in the Alpha Vantage response.'
)
);
return;
}
// Best-effort sanity check that the metadata references AMZN. This does
// not fail the step on its own (the time series above is the primary
// assertion), but it is logged for diagnosis.
const metaData = parsed['Meta Data'];
const symbol = metaData && metaData['2. Symbol'];
if (symbol !== 'AMZN') {
log.warn(
'Meta Data symbol was "' +
symbol +
'", expected "AMZN". Continuing because Time Series (Daily) is present.'
);
}
log.info(
'Alpha Vantage returned ' +
Object.keys(timeSeries).length +
' daily data points for AMZN.'
);
resolve();
});
});
};
// Response capture is configured globally above, so no per-step stepConfig is
// needed here. executeHttpStep records the request/response details into the
// run report per that global configuration.
await synthetics.executeHttpStep(
'verify_alpha_vantage_daily_AMZN',
requestOptions,
validateResponse
);
};
exports.handler = async () => {
return await apiCanary();
};
3. Sample API Response ▸
JSON
{
"Meta Data": {
"1. Information": "Daily Prices (open, high, low, close) and Volumes",
"2. Symbol": "AMZN",
"3. Last Refreshed": "2026-10-16",
"4. Output Size": "Compact",
"5. Time Zone": "US/Eastern"
},
"Time Series (Daily)": {
"2026-10-16": {
"1. open": "255.2200",
"2. high": "255.5400",
"3. low": "248.6000",
"4. close": "250.0000",
"5. volume": "40271250"
},
"2026-10-15": {
"1. open": "250.8900",
"2. high": "255.6000",
"3. low": "248.6500",
"4. close": "254.7600",
"5. volume": "34564192"
},
"2026-10-14": {
"1. open": "258.0100",
"2. high": "259.6500",
"3. low": "252.6600",
"4. close": "254.0800",
"5. volume": "34821020"
},
"2026-10-13": {
"1. open": "259.4400",
"2. high": "262.8350",
"3. low": "258.4200",
"4. close": "258.5800",
"5. volume": "25299540"
},
"2026-10-12": {
"1. open": "262.5000",
"2. high": "263.7000",
"3. low": "259.2700",
"4. close": "259.5300",
"5. volume": "26577896"
},
"2026-10-09": {
"1. open": "256.5000",
"2. high": "262.8000",
"3. low": "256.0000",
"4. close": "262.4300",
"5. volume": "34769999"
},
"2026-10-08": {
"1. open": "259.7400",
"2. high": "259.8599",
"3. low": "253.7800",
"4. close": "254.0600",
"5. volume": "38649939"
},
"2026-10-07": {
"1. open": "254.2300",
"2. high": "260.1400",
"3. low": "253.1700",
"4. close": "259.9200",
"5. volume": "36225813"
},
"2026-10-06": {
"1. open": "253.4000",
"2. high": "256.6750",
"3. low": "251.0800",
"4. close": "256.2900",
"5. volume": "34120787"
},
"2026-10-05": {
"1. open": "250.1900",
"2. high": "254.5262",
"3. low": "250.1800",
"4. close": "251.4000",
"5. volume": "39273944"
},
"2026-10-02": {
"1. open": "251.5050",
"2. high": "253.5577",
"3. low": "250.0200",
"4. close": "251.5200",
"5. volume": "33433392"
},
"2026-10-01": {
"1. open": "251.6050",
"2. high": "251.8300",
"3. low": "246.1167",
"4. close": "248.2300",
"5. volume": "33243918"
},
"2026-09-30": {
"1. open": "246.7900",
"2. high": "252.4400",
"3. low": "246.0800",
"4. close": "249.1500",
"5. volume": "41913110"
},
"2026-09-29": {
"1. open": "246.7050",
"2. high": "248.8389",
"3. low": "245.1400",
"4. close": "246.6700",
"5. volume": "33730401"
},
"2026-09-28": {
"1. open": "246.6250",
"2. high": "247.7699",
"3. low": "244.7250",
"4. close": "246.1500",
"5. volume": "32596709"
},
"2026-09-25": {
"1. open": "248.5600",
"2. high": "250.8775",
"3. low": "247.1800",
"4. close": "249.6700",
"5. volume": "34263902"
},
"2026-09-24": {
"1. open": "246.0200",
"2. high": "250.4300",
"3. low": "245.6000",
"4. close": "249.3800",
"5. volume": "33040052"
},
"2026-09-23": {
"1. open": "253.0000",
"2. high": "253.9900",
"3. low": "247.7600",
"4. close": "249.2700",
"5. volume": "44209157"
},
"2026-09-22": {
"1. open": "255.1100",
"2. high": "259.0000",
"3. low": "253.7800",
"4. close": "254.9800",
"5. volume": "41982569"
},
"2026-09-21": {
"1. open": "256.4000",
"2. high": "259.4900",
"3. low": "253.6000",
"4. close": "258.4500",
"5. volume": "42979407"
},
"2026-09-18": {
"1. open": "252.9200",
"2. high": "255.4300",
"3. low": "251.8800",
"4. close": "253.7100",
"5. volume": "52274713"
},
"2026-09-17": {
"1. open": "251.0650",
"2. high": "252.7300",
"3. low": "249.2400",
"4. close": "251.1900",
"5. volume": "30438790"
},
"2026-09-16": {
"1. open": "248.1000",
"2. high": "249.2600",
"3. low": "244.3000",
"4. close": "245.9600",
"5. volume": "33488488"
},
"2026-09-15": {
"1. open": "252.2400",
"2. high": "253.2700",
"3. low": "247.2200",
"4. close": "248.4200",
"5. volume": "36275442"
},
"2026-09-14": {
"1. open": "253.1500",
"2. high": "255.9500",
"3. low": "250.7400",
"4. close": "253.5400",
"5. volume": "34352766"
},
"2026-09-11": {
"1. open": "254.0900",
"2. high": "257.5900",
"3. low": "253.1400",
"4. close": "256.7800",
"5. volume": "26724121"
},
"2026-09-10": {
"1. open": "250.1100",
"2. high": "253.1500",
"3. low": "249.5800",
"4. close": "251.8900",
"5. volume": "25484814"
},
"2026-09-09": {
"1. open": "253.1200",
"2. high": "254.6900",
"3. low": "250.6500",
"4. close": "252.4000",
"5. volume": "33055487"
},
"2026-09-08": {
"1. open": "256.6750",
"2. high": "257.9900",
"3. low": "254.7500",
"4. close": "256.9700",
"5. volume": "29397994"
},
"2026-09-04": {
"1. open": "259.0700",
"2. high": "261.1200",
"3. low": "255.2900",
"4. close": "258.5100",
"5. volume": "30749912"
},
"2026-09-03": {
"1. open": "256.2000",
"2. high": "259.5000",
"3. low": "256.0000",
"4. close": "258.9000",
"5. volume": "26891531"
},
"2026-09-02": {
"1. open": "254.2550",
"2. high": "256.2400",
"3. low": "253.4000",
"4. close": "254.9800",
"5. volume": "24013334"
},
"2026-09-01": {
"1. open": "254.8300",
"2. high": "255.8200",
"3. low": "251.9300",
"4. close": "254.9200",
"5. volume": "31700056"
},
"2026-08-31": {
"1. open": "263.8250",
"2. high": "264.3600",
"3. low": "257.1200",
"4. close": "259.7700",
"5. volume": "46089422"
},
"2026-08-28": {
"1. open": "258.3200",
"2. high": "267.5600",
"3. low": "257.7800",
"4. close": "266.4300",
"5. volume": "49547427"
},
"2026-08-27": {
"1. open": "259.2300",
"2. high": "259.6600",
"3. low": "255.0200",
"4. close": "256.2600",
"5. volume": "35927807"
},
"2026-08-26": {
"1. open": "261.2750",
"2. high": "262.0500",
"3. low": "258.2400",
"4. close": "260.2800",
"5. volume": "21528373"
},
"2026-08-25": {
"1. open": "262.5100",
"2. high": "263.8900",
"3. low": "259.8300",
"4. close": "261.0600",
"5. volume": "25550214"
},
"2026-08-24": {
"1. open": "259.6000",
"2. high": "263.3200",
"3. low": "259.0500",
"4. close": "262.0700",
"5. volume": "28070483"
},
"2026-08-21": {
"1. open": "260.7400",
"2. high": "261.0900",
"3. low": "257.0350",
"4. close": "258.6300",
"5. volume": "35722956"
},
"2026-08-20": {
"1. open": "263.1600",
"2. high": "263.8400",
"3. low": "259.5200",
"4. close": "260.1100",
"5. volume": "28374098"
},
"2026-08-19": {
"1. open": "260.8450",
"2. high": "266.4000",
"3. low": "258.5800",
"4. close": "265.8400",
"5. volume": "35762439"
},
"2026-08-18": {
"1. open": "260.6300",
"2. high": "262.1800",
"3. low": "257.7300",
"4. close": "259.4500",
"5. volume": "33171263"
},
"2026-08-17": {
"1. open": "265.4400",
"2. high": "265.7500",
"3. low": "258.3390",
"4. close": "261.3100",
"5. volume": "43896516"
},
"2026-08-14": {
"1. open": "264.8750",
"2. high": "265.8100",
"3. low": "262.4200",
"4. close": "262.6500",
"5. volume": "27251660"
},
"2026-08-13": {
"1. open": "267.2350",
"2. high": "269.5800",
"3. low": "264.7050",
"4. close": "265.1300",
"5. volume": "32170151"
},
"2026-08-12": {
"1. open": "273.1800",
"2. high": "273.4600",
"3. low": "267.1000",
"4. close": "267.2800",
"5. volume": "29941093"
},
"2026-08-11": {
"1. open": "278.6900",
"2. high": "278.8400",
"3. low": "271.3600",
"4. close": "272.2700",
"5. volume": "31895708"
},
"2026-08-10": {
"1. open": "274.0100",
"2. high": "280.1400",
"3. low": "273.6001",
"4. close": "278.0900",
"5. volume": "35731907"
},
"2026-08-07": {
"1. open": "272.8700",
"2. high": "278.3100",
"3. low": "272.7500",
"4. close": "274.4800",
"5. volume": "33861436"
},
"2026-08-06": {
"1. open": "272.7650",
"2. high": "275.4800",
"3. low": "271.0610",
"4. close": "272.2600",
"5. volume": "30672901"
},
"2026-08-05": {
"1. open": "281.5900",
"2. high": "282.7900",
"3. low": "270.7300",
"4. close": "272.6500",
"5. volume": "45119804"
},
"2026-08-04": {
"1. open": "276.0600",
"2. high": "281.0700",
"3. low": "275.8200",
"4. close": "277.4200",
"5. volume": "69748055"
},
"2026-08-03": {
"1. open": "278.2900",
"2. high": "287.2000",
"3. low": "278.0000",
"4. close": "284.0200",
"5. volume": "90830221"
},
"2026-07-31": {
"1. open": "265.0000",
"2. high": "273.2300",
"3. low": "262.0100",
"4. close": "271.5800",
"5. volume": "129054771"
},
"2026-07-30": {
"1. open": "233.3500",
"2. high": "239.8236",
"3. low": "231.0600",
"4. close": "235.5000",
"5. volume": "101839774"
},
"2026-07-29": {
"1. open": "229.3150",
"2. high": "232.8200",
"3. low": "226.1600",
"4. close": "226.6500",
"5. volume": "44957524"
},
"2026-07-28": {
"1. open": "232.8500",
"2. high": "233.1100",
"3. low": "228.1000",
"4. close": "230.8600",
"5. volume": "44521597"
},
"2026-07-27": {
"1. open": "235.6650",
"2. high": "235.8900",
"3. low": "230.9900",
"4. close": "231.3900",
"5. volume": "34999495"
},
"2026-07-24": {
"1. open": "234.3800",
"2. high": "234.9500",
"3. low": "231.3400",
"4. close": "232.1100",
"5. volume": "35017357"
},
"2026-07-23": {
"1. open": "236.2600",
"2. high": "238.3499",
"3. low": "232.0516",
"4. close": "233.6600",
"5. volume": "47465337"
},
"2026-07-22": {
"1. open": "248.2650",
"2. high": "248.4500",
"3. low": "242.4500",
"4. close": "244.8500",
"5. volume": "34112732"
},
"2026-07-21": {
"1. open": "249.1050",
"2. high": "249.3400",
"3. low": "246.4200",
"4. close": "247.5500",
"5. volume": "27732064"
},
"2026-07-20": {
"1. open": "248.7600",
"2. high": "252.8900",
"3. low": "248.0000",
"4. close": "249.9900",
"5. volume": "32406481"
},
"2026-07-17": {
"1. open": "244.4600",
"2. high": "250.2400",
"3. low": "243.5900",
"4. close": "247.2300",
"5. volume": "43572361"
},
"2026-07-16": {
"1. open": "255.1200",
"2. high": "258.0825",
"3. low": "248.0000",
"4. close": "249.8900",
"5. volume": "45343709"
},
"2026-07-15": {
"1. open": "249.7500",
"2. high": "256.4800",
"3. low": "249.7500",
"4. close": "254.9600",
"5. volume": "45240622"
},
"2026-07-14": {
"1. open": "245.5500",
"2. high": "248.5600",
"3. low": "243.8000",
"4. close": "247.4900",
"5. volume": "30108054"
},
"2026-07-13": {
"1. open": "244.6800",
"2. high": "249.6500",
"3. low": "244.1800",
"4. close": "247.3100",
"5. volume": "34636091"
},
"2026-07-10": {
"1. open": "249.5500",
"2. high": "251.0300",
"3. low": "244.4100",
"4. close": "245.3400",
"5. volume": "31653997"
},
"2026-07-09": {
"1. open": "239.8200",
"2. high": "247.5000",
"3. low": "238.2500",
"4. close": "247.0400",
"5. volume": "38091688"
},
"2026-07-08": {
"1. open": "244.2700",
"2. high": "244.8000",
"3. low": "240.5200",
"4. close": "243.6200",
"5. volume": "29653043"
},
"2026-07-07": {
"1. open": "246.9750",
"2. high": "248.9300",
"3. low": "242.7000",
"4. close": "245.9800",
"5. volume": "40579603"
},
"2026-07-06": {
"1. open": "243.7950",
"2. high": "246.0400",
"3. low": "240.8800",
"4. close": "244.1600",
"5. volume": "40044034"
},
"2026-07-02": {
"1. open": "241.6050",
"2. high": "246.7200",
"3. low": "241.0800",
"4. close": "242.6700",
"5. volume": "48298137"
},
"2026-07-01": {
"1. open": "239.7500",
"2. high": "244.9000",
"3. low": "234.9000",
"4. close": "241.7000",
"5. volume": "53829851"
},
"2026-06-30": {
"1. open": "237.3500",
"2. high": "241.5400",
"3. low": "237.1710",
"4. close": "238.3400",
"5. volume": "66228262"
},
"2026-06-29": {
"1. open": "234.2150",
"2. high": "249.7100",
"3. low": "233.8000",
"4. close": "240.1400",
"5. volume": "77619228"
},
"2026-06-26": {
"1. open": "227.2050",
"2. high": "233.9000",
"3. low": "226.1250",
"4. close": "232.6900",
"5. volume": "248372085"
},
"2026-06-25": {
"1. open": "232.0200",
"2. high": "232.3200",
"3. low": "225.5500",
"4. close": "227.0100",
"5. volume": "77858478"
},
"2026-06-24": {
"1. open": "233.8450",
"2. high": "242.4199",
"3. low": "232.9500",
"4. close": "234.2700",
"5. volume": "70282581"
},
"2026-06-23": {
"1. open": "232.5500",
"2. high": "236.8700",
"3. low": "232.0000",
"4. close": "234.1100",
"5. volume": "60492560"
},
"2026-06-22": {
"1. open": "240.0800",
"2. high": "242.0000",
"3. low": "232.2400",
"4. close": "232.7900",
"5. volume": "68388526"
},
"2026-06-18": {
"1. open": "240.1200",
"2. high": "245.7300",
"3. low": "236.0200",
"4. close": "244.3900",
"5. volume": "75624415"
},
"2026-06-17": {
"1. open": "244.9000",
"2. high": "245.9100",
"3. low": "236.0000",
"4. close": "237.5000",
"5. volume": "44780767"
},
"2026-06-16": {
"1. open": "248.0000",
"2. high": "249.5100",
"3. low": "245.4511",
"4. close": "246.0000",
"5. volume": "35187406"
},
"2026-06-15": {
"1. open": "245.0200",
"2. high": "247.8050",
"3. low": "244.7300",
"4. close": "246.0200",
"5. volume": "41711576"
},
"2026-06-12": {
"1. open": "243.2100",
"2. high": "243.3600",
"3. low": "233.5900",
"4. close": "238.5500",
"5. volume": "51251141"
},
"2026-06-11": {
"1. open": "237.9300",
"2. high": "242.1400",
"3. low": "235.1800",
"4. close": "241.5100",
"5. volume": "41335399"
},
"2026-06-10": {
"1. open": "243.6050",
"2. high": "244.0650",
"3. low": "237.4500",
"4. close": "238.0000",
"5. volume": "38590237"
},
"2026-06-09": {
"1. open": "247.7300",
"2. high": "250.4300",
"3. low": "240.4000",
"4. close": "244.1900",
"5. volume": "44425363"
},
"2026-06-08": {
"1. open": "246.6800",
"2. high": "249.4200",
"3. low": "243.3600",
"4. close": "245.2200",
"5. volume": "33899525"
},
"2026-06-05": {
"1. open": "254.2550",
"2. high": "256.3800",
"3. low": "245.7800",
"4. close": "246.0300",
"5. volume": "55607844"
},
"2026-06-04": {
"1. open": "253.1200",
"2. high": "255.8300",
"3. low": "251.7500",
"4. close": "253.7900",
"5. volume": "35609769"
},
"2026-06-03": {
"1. open": "254.7000",
"2. high": "257.0900",
"3. low": "247.7100",
"4. close": "250.0200",
"5. volume": "51394191"
},
"2026-06-02": {
"1. open": "257.1600",
"2. high": "261.2025",
"3. low": "254.3700",
"4. close": "256.5200",
"5. volume": "41810982"
},
"2026-06-01": {
"1. open": "266.2850",
"2. high": "266.6300",
"3. low": "260.7000",
"4. close": "261.2600",
"5. volume": "53604380"
},
"2026-05-29": {
"1. open": "271.2900",
"2. high": "274.7500",
"3. low": "269.6400",
"4. close": "270.6400",
"5. volume": "54749561"
},
"2026-05-28": {
"1. open": "272.2700",
"2. high": "274.5000",
"3. low": "267.4400",
"4. close": "274.0000",
"5. volume": "40630385"
},
"2026-05-27": {
"1. open": "266.1500",
"2. high": "272.4100",
"3. low": "265.7001",
"4. close": "271.8500",
"5. volume": "40061864"
}
}
}
4. API Error ▾
The API canary occasionally fails. To get more context on the issue, we can review the HTTP response as well as the logs.
Fig 1: Reviewing the HTTP response and logs of a failed API canary run
Note: Alpha Vantage did not return daily time-series data: We have detected your API key as XXXXXXXXXXXXXXXX and our standard API rate limit is 25 requests per day. Please subscribe to any of the premium plans at https://www.alphavantage.co/premium/ to instantly remove all daily rate limits.