title: How do I re-tag an image in ECR?
body: <p>I'm trying to follow along with <a href="https://docs.aws.amazon.com/AmazonECR/latest/userguide/image-retag.html" rel="nofollow noreferrer">Retagging an Image with the AWS CLI</a> and am beginning to suspect this guide is out-of-date. I have a number of Docker images pushed into an ECR repository - let's call it &quot;myappserver.&quot;
  And so I can run commands like this one to see a list of all the images in the ECR repository:</p>
  <pre><code>aws ecr describe-images --repository-name myappserver
  </code></pre>
  <p>The output I get from that command looks something like this:</p>
  <pre><code>{
      &quot;imageDetails&quot;: [
          {
              &quot;registryId&quot;: &quot;123456789012&quot;,
              &quot;repositoryName&quot;: &quot;myappserver&quot;,
              &quot;imageDigest&quot;: &quot;sha256:1234...&quot;,
              &quot;imageSizeInBytes&quot;: 33805114,
              &quot;imagePushedAt&quot;: 1525881170.0
          },
          {
              &quot;registryId&quot;: &quot;123456789012&quot;,
              &quot;repositoryName&quot;: &quot;myappserver&quot;,
              &quot;imageDigest&quot;: &quot;sha256:1234...&quot;,
              &quot;imageTags&quot;: [
                  &quot;latest&quot;
              ],
              &quot;imageSizeInBytes&quot;: 333805137,
              &quot;imagePushedAt&quot;: 1525892193.0
          },
          ...
      ]
  }
  </code></pre>
  <p>Because not all of my images have tags any more, I want to identify them by imageDigest (instead of imageTag like the guide does), which should be fine. However, the command that the guide offers doesn't seem to work any more. It says:</p>
  <blockquote>
  <p>Use the batch-get-image command to get the image manifest for the image to retag and write it to an environment variable. In this example, the manifest for an image with the tag, latest, in the repository, amazonlinux, is written to the environment variable, MANIFEST.</p>
  <p>MANIFEST=$(aws ecr batch-get-image --repository-name amazonlinux --image-ids imageTag=latest --query images[].imageManifest --output text)</p>
  </blockquote>
  <p>So, naturally, I try to run this command:</p>
  <pre><code>aws ecr batch-get-image --repository-name myappserver --image-ids imageDigest=sha256:1234... --query images[].imageManifest --output text
  </code></pre>
  <p>But the response I get in the terminal is:</p>
  <pre><code>zsh: no matches found: images[].imageManifest
  </code></pre>
  <p>Interestingly enough, if I omit the last two parameters (<code>--query images[].imageManifest</code> and <code>--output text</code>) then that command does succeed and returns a bit of JSON. So I tried to copy/paste that JSON by hand into an environment variable - specifically copying the section labeled &quot;imageManifest.&quot; Then, using that environment variable (which I've named <code>MANIFEST</code> to stay consistent with the nomenclature that the guide uses), I tried to run this command:</p>
  <pre><code>aws ecr put-image --repository-name myappserver --image-tag new-tag --image-manifest &quot;$MANIFEST&quot;
  </code></pre>
  <p>However, that results in the following error message:</p>
  <pre><code>An error occurred (InvalidParameterException) when calling the PutImage operation: Invalid parameter at 'ImageManifest' failed to satisfy constraint: 'Invalid JSON syntax'
  </code></pre>
  <p>As far as I can tell, the JSON output that I copied into the <code>put-image</code> command <strong>is valid</strong>, despite that error. And I'm also confused why I'm unable to run the <code>batch-get-image</code> command with the provided arguments. What can I do to get these commands working, and to add tags to my image?</p>