简体   繁体   中英

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?

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 .

You have created an ERC repo and you have up uploaded an image to it? This might help, I saw this which looks kinda similiar to a part of what you are trying to achieve: https://github.com/aws-samples/amazon-ecs-catsndogs-workshop/blob/master/Lab-6-Artifacts/dogs/buildspec.yml

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM