title: How to use AWS CLI to deploy lambda function to specific alias or version?
body: <p>Before I have Lambda version and alias, based on the API <a href="https://docs.aws.amazon.com/cli/latest/reference/lambda/update-function-code.html" rel="nofollow noreferrer">update-function-code</a> I can successfully deploy by</p>
  
  <pre><code>aws lambda update-function-code --function-name myFunction --zip-file fileb://archive.zip
  </code></pre>
  
  <p>After I added version and alias, I have Lambda version </p>
  
  <ul>
  <li><strong>$LATEST</strong> (default)</li>
  <li><strong>1</strong></li>
  <li><strong>2</strong></li>
  </ul>
  
  <p>and alias</p>
  
  <ul>
  <li><strong>staging</strong> (point to version <strong>1</strong>)</li>
  <li><strong>prod</strong> (point to version <strong>2</strong>)</li>
  </ul>
  
  <p>I try to deploy to <strong>staging</strong> (version <strong>1</strong>),</p>
  
  <hr>
  
  <h2>1st Try</h2>
  
  <pre><code>aws lambda update-function-code --function-name arn:aws:lambda:us-west-2:123456789000:function:myFunction:staging --zip-file fileb://archive.zip
  </code></pre>
  
  <p>gave error</p>
  
  <blockquote>
    <p>Current operation does not support
    versions other than $LATEST. Please set the version to $LATEST or do
    not set a version in your request.</p>
  </blockquote>
  
  <hr>
  
  <h2>2nd Try</h2>
  
  <pre><code>aws lambda update-function-code --function-name myFunction --zip-file fileb://archive.zip --s3-object-version 1
  </code></pre>
  
  <p>or</p>
  
  <pre><code>aws lambda update-function-code --function-name myFunction --zip-file fileb://archive.zip --s3-object-version staging
  </code></pre>
  
  <p>gave error</p>
  
  <blockquote>
    <p>Please do not provide other FunctionCode
    parameters when providing a ZipFile.</p>
  </blockquote>
  
  <hr>
  
  <p>How to use AWS CLI to deploy lambda function to specific alias or version correctly? Thanks</p>