

文档 AWS SDK 示例 GitHub 存储库中还有更多 [S AWS DK 示例](https://github.com/awsdocs/aws-doc-sdk-examples)。

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 将 `PublishVersion` 与 CLI 配合使用
<a name="lambda_example_lambda_PublishVersion_section"></a>

以下代码示例演示如何使用 `PublishVersion`。

------
#### [ CLI ]

**AWS CLI**  
**发布函数的新版本**  
以下 `publish-version` 示例发布了 `my-function` Lambda 函数的新版本。  

```
aws lambda publish-version \
    --function-name my-function
```
输出：  

```
{
    "TracingConfig": {
        "Mode": "PassThrough"
    },
    "CodeSha256": "dBG9m8SGdmlEjw/JYXlhhvCrAv5TxvXsbL/RMr0fT/I=",
    "FunctionName": "my-function",
    "CodeSize": 294,
    "RevisionId": "f31d3d39-cc63-4520-97d4-43cd44c94c20",
    "MemorySize": 128,
    "FunctionArn": "arn:aws:lambda:us-west-2:123456789012:function:my-function:3",
    "Version": "2",
    "Role": "arn:aws:iam::123456789012:role/service-role/MyTestFunction-role-zgur6bf4",
    "Timeout": 3,
    "LastModified": "2019-09-23T18:32:33.857+0000",
    "Handler": "my-function.handler",
    "Runtime": "nodejs10.x",
    "Description": ""
}
```
*有关更多信息，请参阅 [AWS Lambda 开发人员指南中的配置 Lambda AWS 函数别名](https://docs.aws.amazon.com/lambda/latest/dg/aliases-intro.html)。*  
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[PublishVersion](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/lambda/publish-version.html)*中的。

------
#### [ PowerShell ]

**适用于 PowerShell V4 的工具**  
**示例 1：本示例创建了 Lambda 函数代码的现有快照版本**  

```
Publish-LMVersion -FunctionName "MylambdaFunction123" -Description "Publishing Existing Snapshot of function code as a  new version through Powershell"
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [PublishVersion](https://docs.aws.amazon.com/powershell/v4/reference)中的。

**适用于 PowerShell V5 的工具**  
**示例 1：本示例创建了 Lambda 函数代码的现有快照版本**  

```
Publish-LMVersion -FunctionName "MylambdaFunction123" -Description "Publishing Existing Snapshot of function code as a  new version through Powershell"
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [PublishVersion](https://docs.aws.amazon.com/powershell/v5/reference)中的。

------