NewAg-ApiKey 格式错误

NewAg-ApiKey format errors

我正在尝试 运行 aws powershell 中的 NewAg-ApiKey cmdlet。我不确定 StageKeys 的格式。有人可以澄清一下吗?

目前正在将 New-AgApiKey 写为:

New-AGApiKey -CustomerId '11' -Description 'aa' -Enabled $True -GenerateDistinctId $True -Name 'newAPIKey'-StageKeys [{"RestApiId":'yz50sp19a7'},{"StageName":'wh1'}] -Force

并出现以下错误

At C:\Users\sgoswami\Desktop\Scripts\create1.ps1:2 char:132 + ... $True -Name 'newAPIKey'-StageKeys [{"RestApiId":'yz50sp19a7'},{"Stag ... + ~~~~~~~~~~~~~ Unexpected token ':'yz50sp19a7'' in expression or statement. At C:\Users\sgoswami\Desktop\Scripts\create1.ps1:2 char:159 + ... Key'-StageKeys [{"RestApiId":'yz50sp19a7'},{"StageName":'wh1'}] -Forc ... + ~~~~~~ Unexpected token ':'wh1'' in expression or statement. + CategoryInfo : ParserError: (:) [], ParseException + FullyQualifiedErrorId : UnexpectedToken

尝试创建完全没有 StageKey 的 ApiKey。它不是必需的参数,并且根据 New-AGApiKey documentation this parameter has been deprecated in favor of usage plans:

-StageKey StageKey[]

DEPRECATED FOR USAGE PLANS - Specifies stages associated with the API key.
Required? False
Position? Named
Accept pipeline input? False

此选项同样已在 CLI 和其他 SDK 中弃用。

如果您仍然需要使用 StageKeys,Amazon.APIGateway.Model.StageKey type is defined here,请参见适用于 .NET 的 AWS 开发工具包文档。您可以按如下所述在 powershell 中创建此类型的新实例,其中具有匹配 属性 名称和值的 powershell 用作新对象的输入:

$obj = New-Object Amazon.APIGateway.Model.StageKey -Property @{ RestApiId = "myId"; StageName = "myName" }

验证类型是否正确:

$obj | get-member

   TypeName: Amazon.APIGateway.Model.StageKey

Name        MemberType Definition
----        ---------- ----------
Equals      Method     bool Equals(System.Object obj)
GetHashCode Method     int GetHashCode()
GetType     Method     type GetType()
ToString    Method     string ToString()
RestApiId   Property   string RestApiId {get;set;}
StageName   Property   string StageName {get;set;}