7

"Invalid action configuration Did not find the image definition file imagedefinitions.json in the input artifacts ZIP file. Verify the file is stored in your pipeline's Amazon S3 artifact bucket"

getting this error, i did not user codebuild in AWS and image is directil pushed to ECR , we build that image with maven, i have uploaded imagedefinitions.json to the artifi bucket , i also zipped that file ,but nothing worked,

can any one suggest anything

Akshay
  • 91
  • 1
  • 1
  • 7
  • Hey @Akshay , are you using a Deploy stage from CodePipeline? if so, you need to create either: a source s3 action where you have the imagedefinitions file, or a CodeBuild step to create that same file and include it in output artifacts. Here: https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-cd-pipeline.html – marianogg9 Jan 27 '20 at 13:39

2 Answers2

20

When you are using ECR as a source, ECR generates an artifact file called 'imageDetail.json' which is of the format [1]. But the ECS Deploy stage requires a file called 'imagedefinitions.json' which is formatted differently [2].

To provide the required file, please add a CodeBuild step betweenn source and deploy with the following buildspec: (Basically converting the file)

version: 0.2
phases:
    install:
        runtime-versions:
            docker: 18
    build:
        commands:
            - apt-get install jq -y
            - ContainerName="todo"
            - ImageURI=$(cat imageDetail.json | jq -r '.ImageURI')
            - printf '[{"name":"CONTAINER_NAME","imageUri":"IMAGE_URI"}]' > imagedefinitions.json
            - sed -i -e "s|CONTAINER_NAME|$ContainerName|g" imagedefinitions.json
            - sed -i -e "s|IMAGE_URI|$ImageURI|g" imagedefinitions.json
            - cat imagedefinitions.json

artifacts:
    files:
        - imagedefinitions.json

Important1: Update 'ContainerName' as it exists in your task definition

Important2: Make sure input artifact of deploy action is BuildArtifact.

  1. https://docs.aws.amazon.com/codepipeline/latest/userguide/file-reference.html#file-reference-ecs-bluegreen
  2. https://docs.aws.amazon.com/codepipeline/latest/userguide/file-reference.html#pipelines-create-image-definitions
shariqmaws
  • 8,152
  • 1
  • 16
  • 35
2

following aws documentation, you can also do it like this in your buildspec:

printf '[{"name":"container_name","imageUri":"image_URI"}]' > imagedefinitions.json

https://docs.aws.amazon.com/codepipeline/latest/userguide/file-reference.html

Jeffrey
  • 452
  • 1
  • 9
  • 22