in blogs/ecs-canary-deployments-pipeline/shared_stack/lambda_functions/remove_previous_canary_components/main.py [0:0]
def _delete_entries_mesh(event):
""" Delete the old entries in AppMesh VirtualRouter """
route = event['Protocol']+'Route'
try:
entries = APPMESH_CLIENT.describe_route(
meshName=event['EnvironmentName'],
routeName=event['MicroserviceName']+'-'+'route',
virtualRouterName=event['MicroserviceName']+'-'+'vr'
)['route']['spec'][route]['action']['weightedTargets']
if len(entries) > 1:
if event['Protocol'].lower() == 'http':
spec={
'httpRoute': {
'action': {
'weightedTargets': [
{
'virtualNode':event['MicroserviceName']+'-'+event['Sha'],
'weight':100
}
]
},
"match": {
"prefix": "/"
},
'retryPolicy': {
'httpRetryEvents': [
'server-error',
'client-error',
'gateway-error'
],
'maxRetries': 2,
'perRetryTimeout': {
'unit': 'ms',
'value': 2000
}
}
}
}
else:
spec={
'tcpRoute': {
'action': {
'weightedTargets': [
{
'virtualNode':event['MicroserviceName']+'-'+event['Sha'],
'weight':100
}
]
},
'timeout': {
'idle': {
'unit': 'ms',
'value': 2000
}
}
}
}
APPMESH_CLIENT.update_route(
meshName=event['EnvironmentName'],
routeName=event['MicroserviceName']+'-'+'route',
spec=spec,
virtualRouterName=event['MicroserviceName']+'-'+'vr'
)
return True
except ClientError as ex:
LOGGER.error("Update route failed with error: %s", ex)
return False