Know How Guide and Hands on Guide for AWS
参考代码
import boto3
def lambda_handler(event, context):
client = boto3.client('directconnect')
responsedx = client.describe_virtual_interfaces()
for v in responsedx['virtualInterfaces']:
vifid = (v['virtualInterfaceId'])
for bgppeer in v['bgpPeers']:
ConnectionState = bgppeer['bgpStatus']
if ConnectionState == "up":
statevalue = 1
else:
statevalue = 0
print ("VIF :",vifid,"state is :",statevalue)
client2 = boto3.client('cloudwatch')
responsecw = client2.put_metric_data(
Namespace="DirectConnectVif",
MetricData=[
{
'MetricName' : "VirtualInterfaceState",
'Dimensions' : [
{
'Name' : "VirtualInterfaceId",
'Value' : vifid
},
],
'Value' : statevalue
}]
)
return "VirtualInterfaceState successfully published"
这个是DX的全面状态指标,建议可以用上,包括告警都创建了