Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Fargate deploy: "Invalid action configuration The AWS ECS container ***** does not exist"

I am using terraform to provision the resources required.

I have a terraform codepipeline resource and the Production stage reads the imagedefinitions.json file to know which images to deploy:

resource "aws_codepipeline" "pipeline" {
  stage {
    name = "Build"
    action {
      name             = "Build"
      category         = "Build"
      owner            = "AWS"
      provider         = "CodeBuild"
      version          = "1"
      input_artifacts  = ["source"]
      output_artifacts = ["imagedefinitions"]
      configuration {
        ProjectName = "${var.project_prefix}-codebuild"
      }
    }
  }
 stage {
    name = "Production"
    action {
      name            = "Deploy"
      category        = "Deploy"
      owner           = "AWS"
      provider        = "ECS"
      input_artifacts = ["imagedefinitions"]
      version         = "1"
      configuration {
        ClusterName = "${var.ecs_cluster_name}"
        ServiceName = "${var.ecs_service_name}"
        FileName    = "imagedefinitions.json"
      }
    }
  }

The imagedefinitions.json file is built during the build phase, from buildspec.yml:

build:
  commands:
    - echo Build started on 'date'
    - echo Building the Docker image...
    - docker build -t $REPOSITORY_URI:latest .
    - docker tag $REPOSITORY_URI:latest $REPOSITORY_URI:$IMAGE_TAG
post_build:
  commands:
    - echo Build completed on 'date'
    - echo Pushing the Docker images...
    - docker push $REPOSITORY_URI:latest
    - docker push $REPOSITORY_URI:$IMAGE_TAG
    - echo Writing image definitions file...
    - printf '[{"name":"docker-image-name","imageUri":"%s"}]' $REPOSITORY_URI:$IMAGE_TAG > imagedefinitions.json  

I am not sure what the name of the image should be in this line:

  • printf '[{"name":"docker-image-name","imageUri":"%s"}]' $REPOSITORY_URI:$IMAGE_TAG > imagedefinitions.json

The error I get repeats the "name" value from this line:

"Invalid action configuration The AWS ECS container docker-image-name does not exist"

What is the name I should have in here?

like image 227
edzillion Avatar asked Dec 10 '22 05:12

edzillion


1 Answers

It looks like you're using the Continuous Deployment with AWS CodePipeline tutorial. From Prerequisites, you should have a task definition, and a service that uses the task definition.

When the ECS Deploy step in the CodePipeline runs, it looks up the task definition for the service you specify, creates a new task definition where it updates the container with the same name as the one in your imagedefinition.json file.

So from your example, I would expect the Task Definition associated with the ECS Service your pipeline is updating to have a container with the name docker-image-name.

like image 113
Jamie Starke Avatar answered Jan 04 '23 17:01

Jamie Starke