I can retrieve the transitgateway metrics fine using code below, but it doesnt work when I do it for the tgw attachment. But I know there is stats because the network manager dashboard shows metrics for the tgw and all the attachment and graphs the values.
The code below works and i get a response array back for the tgw, the region is setup properly etc. The tgw attachment is also in the same region so I use the same cloudwatch object.
The time range asked is identical for both tgw and tgw attachment and they were both created at the same time so i'm pretty sure its not a time range issue.
response = cloudwatch.get_metric_data(
MetricDataQueries=[
{
'Id': 'm1',
'MetricStat': {
'Metric': {
'Namespace': 'AWS/TransitGateway',
'MetricName': 'BytesIn',
'Dimensions': [
{
'Name': 'TransitGateway',
'Value': 'tgw-0456c4c6fe596f58b',
},
]
},
'Period': 360,
'Stat': 'Sum',
'Unit': 'None'
},
'ReturnData': True,
},
],
StartTime=datetime(2020, 10, 1),
EndTime=datetime.now(),
)
Code below brings back an empty array, the return code is 200 and doesnt complain about syntax. the tgw attach id is correct and is actually attached to the above tgw. I know support for granular tgw attach cloud metrics happened recently so maybe its not yet supported via API ?
response_attach = cloudwatch.get_metric_data(
MetricDataQueries=[
{
'Id': 'm1',
'MetricStat': {
'Metric': {
'Namespace': 'AWS/TransitGatewayAttachment',
'MetricName': 'BytesIn',
'Dimensions': [
{
'Name': 'TransitGatewayAttachment',
'Value': 'tgw-attach-08ed0e1d3e5f488d8'
},
]
},
'Period': 360,
'Stat': 'Sum',
'Unit': 'None'
},
'ReturnData': True,
},
],
StartTime=datetime(2020, 10, 1),
EndTime=datetime.now(),
)
Results look like this, no Values results, where as the first set of code to the tgw returns an array in Values. I tried different Stat, Period, MetricName to no avail.
{'MetricDataResults': [{'Id': 'm1', 'Label': 'BytesIn', 'Timestamps': [], 'Values': [], 'StatusCode': 'Complete'}], 'Messages': [], 'ResponseMetadata': {'RequestId': '495f97d5-5862-49f2-b8d0-91346606c88a', 'HTTPStatusCode': 200, 'HTTPHeaders': {'x-amzn-requestid': '495f97d5-5862-49f2-b8d0-91346606c88a', 'content-type': 'text/xml', 'content-length': '490', 'date': 'Sat, 03 Oct 2020 10:57:38 GMT'}, 'RetryAttempts': 0}}
Anything obvious I'm doing wrong ? Thanks in advance.
Your namespace is incorrect:
it should be:
The reason is that
TransitGatewayAttachment
is a dimension withinAWS/TransitGateway
namespace as explained in: