Question: I wanted to create a CodePipeline which builds a container image from CodeCommit source and afterwards deploys the new image in Blue/Green fashion to my ECS service (EC2 launchtype).

* The source stage is CodeCommit, which already includes appspec.json  

as well as taskdef.json
* The build stage is building the new
container & pushing it to ECR successfully, the file
imagedefinition.json is the BuildArtifact created at this step,
containing the container and the recently created image with its
tag corresponding to the CodeCommit commit-id.
* The deploy stage
is made of action "Amazon ECS (Blue/Green)" using the
SourceArtifact and BuildArtifact as InputArtifacts, to take the
appspec and taskdef from the SourceArtifact and the image
description from the BuildArtifact, to finally deploy the new
container in Blue/Green manner.

The problem is with the image definition from the BuildArtifact. The pipeline fails in the Deploy phase with error: 

""
Invalid action configuration
Exception while trying to read the image artifact file from the artifact: BuildArtifact.
""

How to properly configure the "Amazon ECS (Blue/Green)" deploy phase, so that it can use the recently created image and deploy it....by replacing placeholder IMAGE\_NAME inside taskdef.json ?

Any hint highly appreciated :D

Answer: 
Amazon ECS Blue/Green (or CodeDeployToECS) CodePipeline action requires the TaskDefinitionTemplateArtifact parameter (see [1]). 

In addition to the above file note an imageDetail.json is required for ECS Blue/Green deployments (not 'imagedefinition.json'). The file structure and details are available here [2]. Add this file to the root of your deployment artifact/version control. If you do not want to add this file manually you can use the ECR source action to the CodePipeline and configure this with the Image you are using in the ECS service/taskdef.json. This is all discussed at [2] for clarity.

To see how this is all brought together you can also follow the step by step instructions for ECS Blue/Green deployments here [3].

References:

[1] <https://docs.aws.amazon.com/codepipeline/latest/userguide/reference-pipeline-structure.html#action-requirements> : CodePipeline Pipeline Structure Reference - Action Structure Requirements in CodePipeline
[2] <https://docs.aws.amazon.com/codepipeline/latest/userguide/file-reference.html#file-reference-ecs-bluegreen> : Image Definitions File Reference - imageDetail.json File for Amazon ECS Blue/Green Deployment Actions 
[3] <https://docs.aws.amazon.com/codepipeline/latest/userguide/tutorials-ecs-ecr-codedeploy.html> : Tutorial: Create a Pipeline with an Amazon ECR Source and ECS-to-CodeDeploy Deployment
Thanks, to all, this gives me some light into solving the issue.

I would like to add that when you use `aws cli`, `cloudformation`, or `Terraform` to configure `codepipeline`, some parameters and options are not available with the console and setting some variables in these tools like the empty string "" will cause an exception error.

Always check for `codepipeline` settings in the console when you deploy using these tools.

***so the error occur when you defined Image Artifact but not define the placeholder***

**imageDetail.json** can be passed into `codedeploy` using the following methods:

* git source ( codecommit or github ) the file that exist in your app codebase
* ECR source - the file will be autogenerated by ECR, but will use SHA256 instead of the image tag
* `CodeBuild` source - you update the file using `codebuild` buildspec.yml and pass it down to `codedeploy` stage.