title: AWS S3 CLI CP file and add metadata
body: <p>Trying to copy a local file named test.txt to my s3 bucket and add metadata to the file.</p>
  
  <p>But it always prints error:</p>
  
  <p><strong>argument --metadata-directive: Invalid choice, valid choices are: COPY | REPLACE</strong></p>
  
  <p>Is it possible to do this with the cp command, as I understand the docs it should be possible.
  <a href="http://docs.aws.amazon.com/cli/latest/reference/s3/cp.html" rel="noreferrer" title="AWS CLI CP DOCS">AWS CLI CP DOCS</a></p>
  
  <p>This is the commands I've tried:</p>
  
  <pre><code>aws s3 cp test.txt to s3://a-bucket/test.txt --metadata x-amz-meta-cms-id:34533452
  
  aws s3 cp test.txt to s3://a-bucket/test.txt --metadata-directive COPY --metadata x-amz-meta-cms-id:34533452
  
  aws s3 cp test.txt to s3://a-bucket/test.txt --metadata-directive COPY --metadata '{"x-amz-meta-cms-id":"34533452"}'
  
  aws s3 cp test.txt to s3://a-bucket/test.txt --metadata '{"x-amz-meta-cms-id":"34533452"}'
  </code></pre>
  
  <p>aws --version:
  <strong>aws-cli/1.9.7 Python/2.7.10 Darwin/16.1.0 botocore/1.3.7</strong></p>
  
  <p>OS: <strong>macOS Sierra version 10.12.1</strong></p>
  
  <p><strong>Edit</strong></p>
  
  <p>Worth mentioning is that uploading a file without the --metadata flag works fine.</p>
  
  <p>Hmm, I've checked the help for my version of cli with <code>aws s3 cp help</code>
  Turns out it does not list <code>--metadata</code> as an option, as the docs at the given link above does.</p>
  
  <p>If runnig older version of aws cli</p>
  
  <pre><code>Use aws s3api put-object
  </code></pre>
  
  <p>How to upload a file to a bucket and add metadata:</p>
  
  <pre><code>aws s3api put-object --bucket a-bucket --key test.txt --body test.txt --metadata '{"x-amz-meta-cms-id":"34533452"}'
  </code></pre>
  
  <p>Docs: <a href="http://docs.aws.amazon.com/cli/latest/reference/s3/cp.html" rel="noreferrer" title="AWS CLI CP DOCS">AWS S3API DOCS</a></p>