I have an Lambda function to upgrade my ECS. It always works ok for the latest tag.
import boto3
import os
## Setting variables and importing libraries.
region = "us-east-1"
client = boto3.client('ecs', region_name=region)
CONTAINER_NAME = os.environ['NAME']
DOCKER_IMAGE = os.environ['IMAGE']
FAMILY_DEF = os.environ['TASK_DEF']
CLUSTER_NAME = os.environ['CLUSTER']
SERVICE_NAME = os.environ['SERVICE']
print ("IMAGE -> ", DOCKER_IMAGE)
def lambda_handler(event, context):
print("----- START -----")
response = client.register_task_definition(
family=FAMILY_DEF,
networkMode='awsvpc',
containerDefinitions=[
{
'name': CONTAINER_NAME,
'image': DOCKER_IMAGE,
'memory': 300,
'portMappings': [
{
'containerPort': 80,
'hostPort': 80,
'protocol': 'tcp'
},
],
'essential': True,
},
],
)
## TaskDef for updating our service.
response = client.update_service(
cluster=CLUSTER_NAME,
service=SERVICE_NAME,
desiredCount=1,
forceNewDeployment=True,
## how many containers > n * 2 >
deploymentConfiguration={
'maximumPercent': 200,
'minimumHealthyPercent': 100
}
)
print("Updated service named {} cluster named {} with an updated task definition".format(SERVICE_NAME, CLUSTER_NAME))
If DOCKER_IMAGE = to sdasdasdasd.dkr.ecr.us-east-1.amazonaws.com/cdtest:latest it works ok.
If DOCKER_IMAGE = to sdasdasdasd.dkr.ecr.us-east-1.amazonaws.com/cdtest:myTag it gets me the latest (tag) one.
The question is:
How can I get it to update the cluster with the cdtest:myTag and not the /cdtest:latest ? Even when DOCKER_IMAGE = .... cdtest:myTag it always updates the cluster with cdtest:latest image