cdk flags - AWS Cloud Development Kit (AWS CDK) v2

这是 AWS CDK v2 开发者指南。旧版 CDK v1 于 2022 年 6 月 1 日进入维护阶段,并于 2023 年 6 月 1 日终止支持。

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

cdk flags

查看和修改 CDK CLI 的功能标志配置。

功能标志控制 CDK CLI 的行为,您可以使用它们来启用或禁用特定功能。使用cdk flags命令查看您当前的功能标志配置并根据需要对其进行修改。

警告

cdk flags命令正在为 AWS CDK 开发中。该命令的当前功能被认为已准备就绪,可以安全使用。但是,此命令的范围及其功能可能会发生变化。因此,您必须通过提供使用此命令的unstable=flags选项来选择加入。

使用量

$ cdk flags <arguments> <options>

参数

旗帜名

您要查看或修改的特定功能标志的名称。

类型:字符串

必需:否

选项

有关适用于所有 CDK CLI 命令的全局选项列表,请参阅全局选项

--set <BOOLEAN>

修改功能标志配置。

--all <BOOLEAN>

修改或查看所有功能标志。

--recommended <BOOLEAN>

将标志更改为推荐状态。

--default <BOOLEAN>

将标志更改为默认状态。

--unconfigured <BOOLEAN>

修改未配置的功能标志。

--value <STRING>

要将功能标志配置设置为的值。

requireSar g:没错

--safe <BOOLEAN>

启用所有不会影响您的应用程序的功能标志。

--interactive, -i <BOOLEAN>

flags 命令的交互式选项。

示例

查看功能标志配置

运行cdk flags以查看与我们的推荐状态不同的功能标志配置的报告。未配置的标志标有<unset>,表示该标志当前没有值。标志按以下顺序显示:

  • 将标记设置为与我们的建议值不匹配的值

  • 您尚未配置的标志

$ cdk flags --unstable=flags Feature Flag Recommended User * @aws-cdk/... true false * @aws-cdk/... true false * @aws-cdk/... true <unset>

您也可以按以下顺序运行cdk flags --all以查看所有功能标志的报告:

  • 将标记设置为与我们的推荐值相匹配的值

  • 将标记设置为与我们的建议值不匹配的值

  • 您尚未配置的标志

$ cdk flags --unstable=flags --all Feature Flag Recommended User @aws-cdk/... true true * @aws-cdk/... true false * @aws-cdk/... true false * @aws-cdk/... true <unset>

修改功能标志值

要以交互方式修改您的功能标志,请运行cdk flags --interactive(或cdk flags -i)查看菜单选项列表。

要将每个功能标志更改为我们的建议值,请运行cdk flags --set --recommended --all。此命令 up-to-date使用最新的 CDK 功能标志配置来保留您的功能标志配置。请注意,运行此命令可能会覆盖现有的配置值。

$ cdk flags --unstable=flags --set --recommended --all Feature Flag Recommended Value User Value * @aws-cdk/... true false * @aws-cdk/... true false * @aws-cdk/... true <unset> Synthesizing... Resources [~] AWS::S3::Bucket MyBucket └─ [~] Properties └─ [~] Encryption ... Number of stacks with differences: 2 Do you want to accept these changes? (y/n) y Resynthesizing...

如果要保留现有已配置标志的状态,请运行cdk flags --set --recommended --unconfigured。此选项仅将未配置的功能标志更改为我们的推荐值。

$ cdk flags --unstable=flags --set --recommended --unconfigured Feature Flag Recommended Value User Value * @aws-cdk/... true <unset> * @aws-cdk/... true <unset> Synthesizing... Resources [~] AWS::S3::Bucket MyBucket └─ [~] Properties └─ [~] Encryption ├─ [-] None └─ [+] ServerSideEncryptionConfiguration: - ... ... Number of stacks with differences: 2 Do you want to accept these changes? (y/n) y Resynthesizing...

如果要确保任何未配置的功能标志不会干扰您的应用程序,请运行cdk flags --set --default --unconfigured命令将未配置的标志更改为其默认值。例如,如果未配置,@aws-cdk/aws-cloudfront:defaultSecurityPolicyTLSv1.2_2021则在运行cdk synth后会显示一条通知。但是,如果您将该标志设置为其默认状态 (false),则会对其进行配置和关闭,并且不会影响您的应用程序。

$ cdk flags --unstable=flags --set --default --unconfigured Feature Flag Recommended Value User Value * @aws-cdk/... true <unset> * @aws-cdk/... true <unset> Synthesizing... Do you want to accept these changes? (y/n) y Resynthesizing...

检查特定的功能标志

查看有关旗帜的更多信息

除了运行cdk flagscdk flags --all查看您的功能标志配置外,您还可以使用cdk flags "FLAGNAME"来检查特定的功能标志并找出该标志的作用。如果您想了解特定标志及其对应用程序的影响,这可能会很有帮助。

$ cdk flags --unstable=flags "@aws-cdk/aws-cloudfront:defaultSecurityPolicyTLSv1.2_2021" Description: Enable this feature flag to have cloudfront distributions use the security policy TLSv1.2_2021 by default. Recommended Value: true User Value: true

按子字符串筛选标志

您也可以运行cdk flags substring查看所有匹配的功能标志。如果只有一个功能标志与该子字符串匹配,则会显示特定的细节。

$ cdk flags --unstable=flags ebs @aws-cdk/aws-ec2:ebsDefaultGp3Volume Description: When enabled, the default volume type of the EBS volume will be GP3 Recommended Value: true User Value: true

如果多个标志与子字符串匹配,则所有匹配的标志都将显示在表格中。如果输入多个子字符串,则会返回包含任何子字符串的所有匹配标志。

$ cdk flags --unstable=flags s3 lambda Feature Flag Recommended User * @aws-cdk/s3... true false * @aws-cdk/lambda... true false * @aws-cdk/lambda... true <unset>

修改特定标志

如果您需要修改标志的值并希望确保将其设置为正确且受支持的状态,请运行cdk flags --set "FLAGNAME" --value="state"

$ cdk flags --unstable=flags --set "@aws-cdk/aws-cloudfront:defaultSecurityPolicyTLSv1.2_2021" --value="true" Synthesizing... Resources [~] AWS::CloudFront::Distribution MyDistribution └─ [~] Properties └─ [~] DefaultSecurityPolicy ├─ [-] TLSv1.0 └─ [+] TLSv1.2_2021 - ... Number of stacks with differences: 2 Do you want to accept these changes? (y/n) y Resynthesizing...